你可以这样看(大部分是未经测试的代码,但你明白了):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"url: %@", url);
NSLog(@"scheme: %@", [url scheme]);
NSLog(@"query: %@", [url query]);
NSLog(@"host: %@", [url host]);
NSLog(@"path: %@", [url path]);
NSDictionary * dict = [self parseQueryString:[url query]];
NSLog(@"query dict: %@", dict);
}
所以你可以这样做:
NSString * strNoURLScheme =
[strMyURLWithScheme stringByReplacingOccurrencesOfString:[url scheme] withString:@""];
NSLog(@"URL without scheme: %@", strNoURLScheme);
解析查询字符串
- (NSDictionary *)parseQueryString:(NSString *)query
{
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithCapacity:6] autorelease];
NSArray *pairs = [query componentsSeparatedByString:@"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:@"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
return dict;
}