swift 获取推送deviceToken

升级swift3以后,在使用didRegisterForRemoteNotificationsWithDeviceToken这个方法的时候返回的deviceToken的数据类型为Data,打印出来的deviceToken值是“32byte ” 

下面两种方法转打印 deviceToken 

 let device = NSData(data: deviceToken)

   let deviceId = device.description.replacingOccurrences(of:"<", with:"").replacingOccurrences(of:">", with:"").replacingOccurrences(of:" ", with:"")

   print("我的deviceToken:\(deviceId)")

或者

   let str = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

    print(message: str)

posted @ 2018-05-04 11:23  zuidap  阅读(726)  评论(0编辑  收藏  举报