IOS 4 multi-tasking and custom URL schemes

I am trying to implement OAuth safely, as described here: http://fireeagle.yahoo.net/developer/documentation/oauth_best_practice#custom-url-osx . I seem to have hit a stumbling block since I can't figure out how to handle the URL that my application launches when it is in the background.

I registered my oauthtest processing application. I confirmed that oauthtest: // and oauthtest: // callbacktest start my application and work as intended when my application does not work in the background.

I realize

application:(UIApplication *) didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

which is successfully called when my application starts 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 

and

 application:(UIApplication *) handleOpenURL:(NSURL *)url 
Called

and I have no way to get the parameters passed to my application as part of the URL.

Does anyone know how to get the parameters passed to the background application using a custom url scheme?

I know that I could get around this problem by disabling multitasking, but I would prefer not to do this for obvious reasons. Thanks in advance.

+4
source share
1 answer

Here is a sample code that seemed to work for me, tested on 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 run the application for the first time, didFinishLaunching: processes the URL. If I put the application in the background, go back to Safari and touch the link that will bring the application to the foreground, and then handleOpenURL: take care of the URL. Good luck

+7
source

Source: https://habr.com/ru/post/1314763/


All Articles