registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

前端 未结 15 1730
时光说笑
时光说笑 2020-11-29 15:09

When trying to register for push notifications under iOS 8.x:

application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotific         


        
15条回答
  •  失恋的感觉
    2020-11-29 15:35

    You can use this

    if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
        {
            // for iOS 8
            [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    
            [application registerForRemoteNotifications];
        }
        else
        {
            // for iOS < 8
            [application registerForRemoteNotificationTypes:
             (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
        }
    
        // RESET THE BADGE COUNT 
        application.applicationIconBadgeNumber = 0;
    

提交回复
热议问题