我似乎没有找到关于registerUserNotificationSettings的任何文档超出了去年11月(
here)生成的内容,但是我的旧代码在Xcode 7和Swift 2中似乎并不适合我。
我在App Delegate中有这个代码:
let endGameAction = UIMutableUserNotificationAction() endGameAction.identifier = "END_GAME" endGameAction.title = "End Game" endGameAction.activationMode = .Background endGameAction.authenticationrequired = false endGameAction.destructive = true let continueGameAction = UIMutableUserNotificationAction() continueGameAction.identifier = "CONTINUE_GAME" continueGameAction.title = "Continue" continueGameAction.activationMode = .Foreground continueGameAction.authenticationrequired = false continueGameAction.destructive = false let restartGameCategory = UIMutableUserNotificationCategory() restartGameCategory.identifier = "RESTART_CATEGORY" restartGameCategory.setActions([continueGameAction,endGameAction],forContext: .Default) restartGameCategory.setActions([endGameAction,continueGameAction],forContext: .Minimal) application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert,.Badge,.Sound],categories: (NSSet(array: [restartGameCategory])) as Set<NSObject>))
‘Element.Protocol’ does not have a member named ‘Alert’
和
Cannot invoke ‘registerUserNotificationSettings’ with an argument list of type ‘(UIUserNotificationSettings)’
而不是使用(NSSet(array:[restartGameCategory]))将(NSSet(array:[restartGameCategory]))设置为Set< NSObject>设置< UIUserNotificationCategory>)像这样:
原文链接:https://www.f2er.com/swift/320308.htmlapplication.registerUserNotificationSettings( UIUserNotificationSettings( forTypes: [.Alert,categories: (NSSet(array: [restartGameCategory])) as? Set<UIUserNotificationCategory>))