在设置应用程序中禁用它们后继续接收 iOS 推送通知

问题描述:

在我的应用程序中测试远程推送通知期间,我遇到了一些奇怪的行为:

During the testing of remote push notifications in my App I faced some strange behavior:

即使我在设置 App.这是正常的吗?禁用该选项后,我的应用程序应该取消订阅通知本身,还是 iOS 的响应?或者我应该在注册远程通知时做一些特别的事情吗?或者对于沙盒"通知来说可能是正常的?

I keep getting notifications even if I turn off the "notifications enabled" for my application option in settings App. Is that normal? Should my App unsubscribe from getting notifications itself after disabling that option, or it is response of iOS? Or should I do something special when registering for remote notifications? Or maybe its normal for "sandbox" notifications?

在 iPhone 4 上的 iOS 5.1 上测试.

Tested on iOS 5.1 on iPhone 4.

我认为禁用通知的 UI 令人困惑.将通知中心"切换为关闭与禁用通知不同.

The UI for disabling notifications is confusing, I think. Switching 'Notification Centre' to OFF is not the same as disabling notifications.

您都需要单独取消选择警报样式"、徽章应用图标"、声音"和在锁定屏幕中查看".

You all need to deselect the 'Alert Style', the 'Badge App Icon', 'Sounds', and 'View in Lock Screen - all individually.

这是我用来在运行时检查通知设置的代码:

Here's the code I use to examine the notification settings at run-time:

UIRemoteNotificationType notificationSelection = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

BOOL sendMessage;

if (notificationSelection == UIRemoteNotificationTypeNone)
{
    NSLog(@"Push Notifications : DISABLED (%0X)!", notificationSelection);

    sendMessage = NO;
}
else
{
    NSLog(@"Push Notifications : ENABLED (%0X) - hurrah! :-)", notificationSelection);

    if (notificationSelection & UIRemoteNotificationTypeBadge)
    {
        NSLog (@"Push Notifications : Badge");
    }

    if (notificationSelection & UIRemoteNotificationTypeSound)
    {
        NSLog (@"Push Notifications : Sound");
    }

    if (notificationSelection & UIRemoteNotificationTypeAlert)
    {
        NSLog (@"Push Notifications : Alert");
    }

    if (notificationSelection & UIRemoteNotificationTypeNewsstandContentAvailability)
    {
        NSLog (@"Push Notifications : Newstand Content Availability");
    }
}