将Parse推送通知集成到Xcode 7项目(Swift)

0 apple-push-notifications ios parse-platform swift2

我正在将Parse Push通知集成到一个应用程序中,并且已经陷入了Swift 2.0转换.代码是:

if application.respondsToSelector("registerUserNotificationSettings:") {
            let userNotificationTypes: UIUserNotificationType = [.Alert, .Badge, .Sound]
            let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
            application.registerUserNotificationSettings(settings)
            application.registerForRemoteNotifications()
        } else {
            let types: UIUserNotificationType = [.Badge, .Alert, .Sound]
            application.registerForRemoteNotificationTypes(types)
        }
Run Code Online (Sandbox Code Playgroud)

Xcode抱怨"无法将类型'UIUserNotificationType'的值转换为预期的参数类型'UIRemoteNotificationType'

Kai*_*ato 6

请尝试以下代码,因为不推荐使用UIRemoteNotification,请使用registerUserNotificationSettigns设置通知设置.但请记住在苹果的会员中心和解析时配置推送通知,以便它可以工作.您可以按照本教程从步骤1到步骤4,这很棒.https://www.parse.com/tutorials/ios-push-notifications

if application.respondsToSelector("registerUserNotificationSettings:") {
   let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
   application.registerUserNotificationSettings(settings)
   application.registerForRemoteNotifications()
}
Run Code Online (Sandbox Code Playgroud)