【发布时间】:2017-01-18 22:24:42
【问题描述】:
我在 Swift 2 中确实喜欢下面的内容。但它在 Swift 3 中不起作用。我该如何提供这个?如果有人解释一下,那就太好了。
didFinishLaunchingWithOptions
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
和
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Meesage ID \(userInfo["gcm_message_id"]!)")
print(userInfo)
}
我可以进行简单的本地通知,但无法从 Firebase 远程推送通知。
我试过了
UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Alert, .Badge, .Sound]) { (success, error:NSError?) in
if success {
print("Notification access true!")
application.registerForRemoteNotifications()
}
else {
print(error?.localizedDescription)
}
}
和
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Meesage ID \(userInfo["gcm_message_id"]!)")
print(userInfo)
}
还是不行。
【问题讨论】:
-
委托方法的名称略有变化。通过输入每个方法的名称,您应该会在 Swift 3 中看到相应的方法作为建议。
标签: ios swift firebase swift3 firebase-notifications