How to set up push notifications in Swift

后端 未结 11 1204
生来不讨喜
生来不讨喜 2020-11-27 10:48

I am trying to set up a push notification system for my application. I have a server and a developer license to set up the push notification service.

I am currently

11条回答
  •  情书的邮戳
    2020-11-27 11:33

    Thanks for the earlier answers. Xcode has made some changes and here's the SWIFT 2 code that passes XCode 7 code check and supports both iOS 7 and above:

        if #available(iOS 8.0, *) {
            let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
            UIApplication.sharedApplication().registerUserNotificationSettings(settings)
            UIApplication.sharedApplication().registerForRemoteNotifications()
        } else {
            let settings = UIRemoteNotificationType.Alert.union(UIRemoteNotificationType.Badge).union(UIRemoteNotificationType.Sound)
            UIApplication.sharedApplication().registerForRemoteNotificationTypes(settings)
        }
    

提交回复
热议问题