Jaber Shabeek
Jaber Shabeek

Reputation: 186

What delegate method will be called on receiving a push notification if the app is in killed/Force closed (Not in background) state?

I am currently working on a project which needs to store the pushnotification details in the local storage whenever the notification received.

As of now i could able to receive and store the push notification when the app is in foreground and background.

But when the app is force closed, i couldn't able to store the notification, since on receiving the notification am not getting any trigger in the code, if click on the notification in the notification panel then i am getting the trigger in the code.

i want and approach were i can save the notification with out touching the received notification even the app is in killed state.

Upvotes: 1

Views: 3245

Answers (3)

techcraze
techcraze

Reputation: 112

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
   //Check here launchOptions.
    return YES;
}

this method will get called when you click on notification alert if the app is forced closed. Check for launchOptions. If lauchOptions is not nil then notification is present and handle the notification accordingly. You can get the userInfo from launchOptions. userInfo contains all the infromation of push notification.

Upvotes: -1

Natarajan
Natarajan

Reputation: 3271

You can able to receive the PushNotification When your app is not running by setting below configurations.

  1. In your application's settings, Select target > Select Capabilities > Turn On Background Modes and Select Remote Notifications check box.
  2. In your push notification payload, include the "content-available:true".

Now you the iOS will launch your app automatically in background mode, once received a push message with "content-available:true". So you can save your updates in below method.

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

Please refer this doc for more info from apple. Also refer this doc as well.

Thanks!

Upvotes: 0

Crazy Developer
Crazy Developer

Reputation: 3464

You will never get any information about APNS when your app is killed.

Now how you will get detail about notification when app is killed and then you open the app. I had the same problem and here is my solution which I have applied to resolve it.

We have created one table called Notification detail.

When server fire any Push notification same time we saved that in that above table. And when app is launch we fetch all notification by used-id

We also save the last notification-id to manage the badge count.

Upvotes: 2

Related Questions