Keep receiving iOS push notifications after disabling them in settings app

╄→гoц情女王★ 提交于 2019-12-22 08:34:17

问题


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? 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.


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


来源:https://stackoverflow.com/questions/12299393/keep-receiving-ios-push-notifications-after-disabling-them-in-settings-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!