registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

前端 未结 15 1735
时光说笑
时光说笑 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:34

    For iOS<10

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    {
        //-- Set Notification
        if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
        {
               // iOS 8 Notifications
               [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    
               [application registerForRemoteNotifications];
        }
        else
        {
              // iOS < 8 Notifications
              [application registerForRemoteNotificationTypes:
                         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
        }
    
         //--- your custom code
         return YES;
    }
    

    For iOS10

    https://stackoverflow.com/a/39383027/3560390

提交回复
热议问题