Ask for User Permission to Receive UILocalNotifications in iOS 8

前端 未结 5 674
自闭症患者
自闭症患者 2020-11-29 15:54

I have set up local notifications in the App Delegate Using this:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UILocalNotificati         


        
5条回答
  •  情歌与酒
    2020-11-29 16:26

    I just faced the same problem. Seems like in iOS 8 we need to do an additional step, usually done inside:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /*...*/ }
    

    You can use this code if you want to keep it backward compatible:

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
        if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];
        }
    #endif
    

    The system will remember the decision, and will only ask once.

提交回复
热议问题