registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

前端 未结 15 1721
时光说笑
时光说笑 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 the Swift-inclined:

    if let registration: AnyObject = NSClassFromString("UIUserNotificationSettings") { // iOS 8+
        let notificationTypes: UIUserNotificationType = (.Alert | .Badge | .Sound)
        let notificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    
        application.registerUserNotificationSettings(notificationSettings)
    } else { // iOS 7
        application.registerForRemoteNotificationTypes(.Alert | .Badge | .Sound)
    }
    

提交回复
热议问题