简体   繁体   English

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

[英]Keep receiving iOS push notifications after disabling them in settings app

During the testing of remote push notifications in my App I faced some strange behavior: 在我的应用程序中测试远程推送通知期间,我遇到了一些奇怪的行为:

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? 我的应用程序在禁用该选项后是否应取消订阅自动获取通知,或者是iOS的响应? Or should I do something special when registering for remote notifications? 或者我应该在注册远程通知时做些什么特别的事情? Or maybe its normal for "sandbox" notifications? 或者也许是“沙盒”通知的常态?

Tested on iOS 5.1 on iPhone 4. 在iPhone 4上的iOS 5.1上测试。

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");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM