在iphong中把url分割為數值,我的計劃是這樣:
appname://user=jonsmith&message=blah%20blah
這樣我可以將user和message作為兩個NSString接收。有沒有更好的方法?謝謝
假設你的URL是名為url的NSURL
NSMutableDictionary *queryParams = [[NSMutableDictionary alloc] init];
NSArray *components = [[url query] componentsSeparatedByString:@"&"];
for (NSString *component in components) {
NSArray *pair = [component componentsSeparatedByString:@"="];
[queryParams setObject:[[pair objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding]
forKey:[pair objectAtIndex:0]];
}
...
[queryParams release];