将deviceToken由Data类型转换为String

将deviceToken由Data类型转换为String,其实方法很简单,swift当中的具体做法就是:

在 application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 方法中,实现以下代码:

let nsdataStr = NSData(data: deviceToken)
let datastr = nsdataStr.description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
print("deviceToken:(datastr)")

你可能感兴趣的:(将deviceToken由Data类型转换为String)