迅速的本地通知:表达的类型在没有更多上下文的情况下是模棱两可的



我正在尝试实现本地通知,并且在没有更多上下文的情况下,表达式的类型是模棱两可的。

我看过其他相关主题,其中许多主题正在使用较早版本的Xcode(我使用的8.O,iOS 10(,或者提供了与我相同的代码,结果是。如果我错过了答案的帖子,我深表歉意。我从教程网站复制并粘贴了此代码,该代码似乎与许多其他网站上使用的代码相同(并作为其他问题的答案提供(。

此代码旨在征求用户本地通知的许可

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UNNotificationSettings(forTypes: [.Alert , .Badge , .Sound], categories: nil)) // This line sends back the error
    return true
}

谢谢!

根据Swift 3&iOS 10,执行以下操作:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: nil)
    return true
}

相关内容

最新更新