【发布时间】:2018-05-03 07:54:24
【问题描述】:
我正在使用此代码获取通知中心设备令牌。
它在 Swift 3 中工作,但在 Swift 4 中不工作。发生了什么变化?
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
}
【问题讨论】:
-
谢谢@Ahmad 但它的代码已被弃用。
标签: ios swift apple-push-notifications devicetoken