How to update code using enabledRemoteNotificationTypes because it is “not supported in iOS 8”?

前端 未结 3 2101
情书的邮戳
情书的邮戳 2020-12-15 09:11

this is the code i used for the RemoteNotificationType:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
3条回答
  •  [愿得一人]
    2020-12-15 10:00

    You can also use this code:

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
    
        UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
    
        if (types == UIUserNotificationTypeNone) {
            // Do something
        }
    
    } else {
    
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    
        if (types == UIRemoteNotificationTypeNone) {
            // Do something
        }
    }
    

    Or this one if you only want to check the user is registered for remote notifications:

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    
        BOOL isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
    
        if (isRegisteredForRemoteNotifications) { 
            // Do something
        }
    
    } else {
    
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    
        if (types == UIRemoteNotificationTypeNone) {
            // Do something
        }
    }
    

提交回复
热议问题