Receive local notification when app is in background

while the app is in the background didReceiveLocalNotification is not called.

So I am trying to get notification from didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{ 
 UILocalNotification *notification = [launchOptions  objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
//...
}

      

But my app with background mode enabled (using external accessories) When you click on notification didFinishLaunchingWithOptions is not called.

Any other way to get notified?

+3


source to share


1 answer


Checking Apple 's document on notifications, he says:

iOS Note. On iOS, you can determine if an app is launched as a result of a user pressing an action button, or a notification has been sent to an already running app by examining the state of the app. In delegates, implement application: didReceiveRemoteNotification: or application: didReceiveLocalNotification: method, get the value of applicationState and evaluate it. If the value is UIApplicationStateInactive, the user pressed the action button; if Value is UIApplicationStateActive, the application has received a notification.



As far as I know, when your application is in the background and a local notification appears, you will not receive any method call, the notification will be shown to the user, but if the user touches the notification and thus responding to your application, you will receive a call -didReceiveLocalNotification:

.

+3


source







All Articles