jailani
jailani

Reputation: 2270

Handle widget click action when iOS app in foreground

When the widget is clicked I can handle using the following method if the app is not running-

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

But if the app is in the background how to handle the action?

Upvotes: 1

Views: 600

Answers (1)

Yun CHEN
Yun CHEN

Reputation: 6648

handleOpenURL will be called no matter if App is in the background mode or not.

Official document:
If a URL arrives while your app is suspended or running in the background, the system moves your app to the foreground prior to calling this method.

And what influences the calling:

This method is not called if the delegate returns NO from both the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods. (If only one of the two methods is implemented, its return value determines whether this method is called.) If your app implements the applicationDidFinishLaunching: method instead of application:didFinishLaunchingWithOptions:, this method is called to open the specified URL after the app has been initialized.

And it's better to use following method since iOS9.0:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options NS_AVAILABLE_IOS(9_0); 

Upvotes: 3

Related Questions