Multitasking aware applications in iOS 4 and Custom URL Schemes
I'm trying to implement OAuth securely as detailed here: http://fireeagle.yahoo.net/developer/documentation/oauth_best_practice#custom-url-osx. I seem to have hit a stumbling block, as I am unable to figure out how to handle a url which launches my application when in the background.
I have registered my application to handle oauthtest. I have confirmed that oauthtest:// and oauthtest://callbacktest both launch my application and operate as intended when my application is not running in the background.
I am implementing
application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
which is successfully called when my application starts up cold. I can easily get the url passed to my application.
However, if my application开发者_开发百科 is already running in the background, neither
application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
nor
application:(UIApplication *) handleOpenURL:(NSURL *)url
is called and I have no way of getting the parameters passed to my application as part of the URL.
Does anyone know how to get the parameters passed to a backgrounded application by a custom url scheme?
I am aware that I could work around this issue by disabling multitasking, but I would rather not do that for obvious reasons. Thanks in advance.
Here's some sample code that seemed to work for me, tested in iOS4:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"handleOpenURL - %@", [url absoluteURL]);
return YES;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSLog(@"applicationDidFinishLaunching");
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"didFinishLaunchingWithOptions - %@", [launchOptions objectForKey:@"UIApplicationLaunchOptionsURLKey"]);
return NO;
}
If I launch the application for the first time, didFinishLaunching:
handles the URL. If I then put the app in the background, go back to Safari, and tap a link that brings the app back into the foreground, then handleOpenURL:
takes care of the URL. Good luck!
精彩评论