当应用程序处于后台时跳过或禁用 [​​=10=] 通知

Skip or Disable iOS Notification When App Is In Background

我目前正在保存一个标志以在我的用户首选项中禁用通知。我在我的 didReceieveRemoteNotifications 中使用该标志来显示或跳过传入的通知。但是,当我的应用程序在后台时它仍然显示,我相信我的所有方法都设置正确并且没有被击中。有没有办法在应用程序处于后台时捕获此通知并跳过它显示?

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

        if(enabled == nil || [enabled integerValue] == 1) {
            completionHandler(UIBackgroundFetchResultNewData);
        }

来自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.

因此您的推送 应包含 content-available 且值为 1,并且 不包含警报、声音或徽章 键。

在这种情况下,如果您想通知用户,您必须显示 UILocalNotification