swift 擷取推送deviceToken

來源:互聯網
上載者:User

標籤:ring   兩種方法   for   format   AC   cin   $0   cat   ESS   

升級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)

swift 擷取推送deviceToken

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.