如何使用 Swift 2 在 iOS 7 中注册远程通知?

How to register for remote notifications in iOS 7 using Swift 2?

如何使用 Swift 2 在 iOS 7 中注册远程通知?

我试过这个:

UIApplication.sharedApplication().registerForRemoteNotificationTypes(
UIRemoteNotificationType.Badge | 
UIRemoteNotificationType.Sound | 
UIRemoteNotificationType.Alert)

还有这个

UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Alert | .Badge | .Sound)

但是没用。

在 Swift2 中,这些值是 OptionSetType,您可以像这样在数组中使用它们:

UIApplication.sharedApplication().registerForRemoteNotificationTypes([.Alert, .Badge, .Sound])