KexAri KexAri - 4 months ago 50
iOS Question

Trouble converting device token Swift 3

I am trying to convert a device token and using the following code (swift 3):

parameters["device_token"] = request.deviceToken.reduce("", {$0 + String(format: "%02X", $1)}).

However I am getting the compiler error
Binary operator '+' cannot be applied to operands of type Any? and String
. What am I doing wrong here?


try this

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

var token = ""

for i in 0..<deviceToken.count {
 token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])

  print("Registration succeeded!")
  print("Token: ", token)