在Swift 2中注册用户注册设置的更改?

前端之家收集整理的这篇文章主要介绍了在Swift 2中注册用户注册设置的更改?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我似乎没有找到关于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>)像这样:
application.registerUserNotificationSettings(
    UIUserNotificationSettings(
        forTypes: [.Alert,categories: (NSSet(array: [restartGameCategory])) as? Set<UIUserNotificationCategory>))
原文链接:https://www.f2er.com/swift/320308.html

猜你在找的Swift相关文章