Ahmed Adnan Qazzaz
Ahmed Adnan Qazzaz

Reputation: 373

Detect Remote Notifications when application enters foreground

Good day, I have a question about receiving remote notification on iOS, I know that when a n-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo will be called if the app is running or if the app is not running and the user taps on the notification.

But, if the user ignore the notification badge in the lock screen and unlock the iPhone, after that you runs the app,then that function will not be called, so how can I get the received notification !!

Thank You :)

Upvotes: 1

Views: 612

Answers (4)

7vikram7
7vikram7

Reputation: 2824

When the phone is locked, the application is sent to an inactive state by the OS. So the notifications received during this time are as good as notifications received when the app is in the background. And just like any notification received in the background, the app won't get control unless the user taps on the notification in the tray.

Upvotes: 4

Saurabh Prajapati
Saurabh Prajapati

Reputation: 2380

you can do this using following code

 NSDictionary *pushNotificationPayload = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    if(pushNotificationPayload)
    {
        [self application:application didReceiveRemoteNotification:pushNotificationPayload];
    }

Upvotes: 0

Bhadresh Mulsaniya
Bhadresh Mulsaniya

Reputation: 2640

If you ignore the notification from notification center then you can't get it inside application.

Upvotes: 1

TheHungryCub
TheHungryCub

Reputation: 1970

For any condition , check whether user has tapped, or app is in background or is active. You just have to check the application state in

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

    if(application.applicationState == UIApplicationStateActive) {

        //app is currently active, can update badges count here

    }else if(application.applicationState == UIApplicationStateBackground){

        //app is in background, if content-available key of your notification is set to 1, poll to your backend to retrieve data and update your interface here

    }else if(application.applicationState == UIApplicationStateInactive){

        //app is transitioning from background to foreground (user taps notification), do what you need when user taps here

    }

Upvotes: -1

Related Questions