Launch Closed iOS App From Local Notification
Asked Answered
S

2

6

When my iOS application is running in the background it responds fine to

 - (void)application:(UIApplication *)application didReceiveLocalNotification:
    (UILocalNotification *)notification

but when the application is closed it crashes and gives a SIGKILL error.

How can I run a method within the app if it is closed when the notification is received?

Sibelle answered 19/11, 2012 at 5:0 Comment(0)
M
1

You can't run a method in the app when a local notification is received. The notification can provide any combination of an alert, icon badge number, and a sound (<30 secs).

You can run a method when it comes into the foreground again either through the notification or through other means.

When the app is in the background it will call applicationWillEnterForeground: prior to resuming. You can override this method to handle anything needed after the notification. You can override applicationDidEnterBackground: to determine when your app actually enters the background.

Method application:didReceiveLocalNotification: is called when the app receives a notification but is in the foreground. The alert, icon badge number, and sound will not be triggered when the app is in the foreground.

Mcmaster answered 19/11, 2012 at 5:46 Comment(0)
J
6

When you app is closed then when you get notification than on click of notification - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method is called.

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

  UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

  if (localNotif) 
 {
  // code here.
 }
Junna answered 19/11, 2012 at 5:7 Comment(0)
M
1

You can't run a method in the app when a local notification is received. The notification can provide any combination of an alert, icon badge number, and a sound (<30 secs).

You can run a method when it comes into the foreground again either through the notification or through other means.

When the app is in the background it will call applicationWillEnterForeground: prior to resuming. You can override this method to handle anything needed after the notification. You can override applicationDidEnterBackground: to determine when your app actually enters the background.

Method application:didReceiveLocalNotification: is called when the app receives a notification but is in the foreground. The alert, icon badge number, and sound will not be triggered when the app is in the foreground.

Mcmaster answered 19/11, 2012 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.