I would like to split a custom url for app opening in iPhone into values, my scheme would be something like:
appname://user=jonsmith&message=blah%20blah
Where I would like to be able to get "user" and "message" as two NSStrings. Any advice on best approach?
Assuming your url is in an NSURL
object called url
:
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];
Use Google's gtm_dictionaryWithHttpArgumentsString
NSDictionary category
http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSDictionary%2BURLArguments.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With