Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save AlexHedley/3eb964d2e1a0a77690e9 to your computer and use it in GitHub Desktop.

Select an option

Save AlexHedley/3eb964d2e1a0a77690e9 to your computer and use it in GitHub Desktop.
Custom URL Scheme
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"url recieved: %@", url);
NSLog(@"query string: %@", [url query]);
NSLog(@"host: %@", [url host]);
NSLog(@"url path: %@", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(@"query dict: %@", dict);
return YES;
}
//http://www.idev101.com/code/Objective-C/custom_url_schemes.html
- (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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment