Ask for Permission for Local Notifications in iOS 8, but still have the App Support iOS 7

后端 未结 6 1934

I have an app which uses local notifications. In iOS 7 everything works fine, but in iOS 8 the app needs to ask for user permission to display notifications. To ask for perm

6条回答
  •  既然无缘
    2020-12-13 09:50

    I have implemented simply -

    if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
    
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    
    } else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge];
    }
    

提交回复
热议问题