swift3.0 调用注册方法以及deviceToken打印

// 注册获得device Token

UIApplication.shared.registerForRemoteNotifications()

收到回调通知
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

let device = deviceToken.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
print(device)
print("Device Token:\(String(describing: deviceToken))")

}
然而打印的数据一直是
32bytes
Device Token:32 bytes

改成下面的方法就可以了:
let device = NSData(data: deviceToken)
let deviceId = device.description.replacingOccurrences(of:"<", with:"").replacingOccurrences(of:">", with:"").replacingOccurrences(of:" ", with:"")

你可能感兴趣的:(swift3.0 调用注册方法以及deviceToken打印)