Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip or Disable iOS Notification When App Is In Background

I am currently saving a flag to disable notifiations in my user preferences. I use that flag in my didReceieveRemoteNotifications to show or skip the notification that comes in. However, when my app is in the background it still shows and I believe I have all my methods setup correctly and it's not being hit. Is there a way to catch this notification while app is in the background and skip it from showing?

  NSNumber* enabled = [Helper getBooleanPreference:[Config subscriptionsEnabled]];

        if(enabled == nil || [enabled integerValue] == 1) {
            completionHandler(UIBackgroundFetchResultNewData);
        }
like image 534
Mike Flynn Avatar asked Jan 17 '17 18:01

Mike Flynn


1 Answers

From Apple documentation

The sending of a silent notification requires a special configuration of the notification’s payload. If your payload is not configured properly, the notification might be displayed to the user instead of being delivered to your app in the background. In your payload, make sure the following conditions are true:

The payload’s aps dictionary must include the content-available key with a value of 1.

The payload’s aps dictionary must not contain the alert, sound, or badge keys.

So your push should contain content-available with value 1 and not contain alert, sound, or badge keys.

In that case you have to show UILocalNotification if you want to notify the user.

like image 116
Sander Avatar answered Nov 15 '22 13:11

Sander