0

I am integrating Klaviyo Swift SDK in out React Native Project which has Objective-C for iOS.

To integrate Swift sdk, I have written a package and through that I am setting push token to Klaviyo SDK.

But the resulting APN token is bad (this message I have received from Klaviyo push notification campaign).

I am using PushNotificationIOS to get device token in Javascript and I use this to send to package.

My token is:

let tokenString = "80263c753804d9356a12e47d3e3b64145bba8bf4b1d330cbf7d38dc4f60dc7c811f505086fc8b43b1cabc583724cd11ce98edfdf6cf8db44045ff092d232c35886a058710b3ae73bddda920de153a58a"

I have converted it to Data as Klaviyo SDK accepts in Data so I am doing:

Data(tokenString.utf8)

and internally Klaviyo Swift SDK does:

tokenData.map { String(format: "%02.2hhx", $0) }.joined()

and the resulting token is:

38303236336337353338303464393335366131326534376433653362363431343562626138626634623164333330636266376433386463346636306463376338313166353035303836666338623433623163616263353833373234636431316365393865646664663663663864623434303435666630393264323332633335383836613035383731306233616537336264646461393230646531353361353861

This result should match with tokenString.

Need help on this.

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Vijay
  • 29
  • 3
  • What is the resulting token supposed to be? Where's the Objective-C part of this question? All I see if Swift code. – HangarRash Aug 05 '23 at 04:57
  • In AppDelegate.m file under didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken We have [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; – Vijay Aug 05 '23 at 05:01
  • See https://stackoverflow.com/questions/26501276/converting-hex-string-to-nsdata-in-swift for the needed way to convert your `tokenString` into `Data` such that the resulting token will match the original token string. – HangarRash Aug 05 '23 at 05:03
  • The app delegate method is already giving you `NSData`. Why do you convert that to a `String` and then back into `Data`? Why not directly pass the original data and skip all of the conversions? – HangarRash Aug 05 '23 at 05:08
  • I am not converting it to String. PushNotificationIOS provides me this token in JS code. I am using this token to set to Klaviyo SDK. Klaviyo SDK is in Swift and I want to use functionality as per user functionality. – Vijay Aug 05 '23 at 05:12
  • Then you need to use one of the answers in the link I provided to convert `tokenString` into `tokenData` instead of using `Data(tokenString.ut8)`. – HangarRash Aug 05 '23 at 05:22

0 Answers0