iPhone SDK File Handler with iOS 4 Background Processes
The "application:applicationDidFinishLaunchingWithOptions:" message does not get called when an application is sitting in the background in iOS 4, and I'm trying to figure out how to be notified when the application is brought back into the foreground by another application.
My application registers itself as a handler for certain file types, and Safari and other supported applications allow passing the files over to my app. This works great if the app is closed before I try to use it, but fails otherwise.
In my application:applicationDidFinishLaunchingWithOptions: I have:
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if([url isFileURL]) {
}
[self.window makeKeyAndVisible];
return YES;
As stated开发者_开发技巧 already, this works great so far for starting the app when it's not sitting in the background - but when I switch back over to Safari or Mail and try to open a new file that is supported, my application wakes up from the background and becomes active again but I can't see any "withOptions" overrides for application:applicationWillEnterForeground: or any way to identify what was passed in when it enters the foreground.
What would be the appropriate way to receive these "open file notifications" when the application is in the background?
Appears that using application:openURL:sourceApplication:annotation: is the better approach to receiving these notifications. It is called when the application is launched for the first time, and when it becomes active again as well.
I've moved my application:applicationDidFinishLoadingWithOptions: code into application:openURL:sourceApplication:annotation: for handling the file passed to the application, and it works in all cases now.
To be notified when your app becomes the foreground app, register some object to receive UIApplicationDidBecomeActiveNotification
精彩评论