Unable to set push token in React Native Project
Closed this issue · 2 comments
Description
I have created a react native package for Klaviyo Swift SDK for our RN project which is using Objective c.
I am using package to set pushToken to Klaviyo SDK.
I have device token in string which is provided by PushNotificationIOS in JS code but Klaviyo SDK accepts Data .
I tried Data(token.utf8) but this is generating bad token.
I am not sure what to do now.
Checklist
- I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
- If possible, I've reproduced the issue using the
main
branch of this package. - This issue hasn't been addressed in an existing GitHub issue or discussion.
Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
The Klaviyo Swift SDK version information
No response
Destination operating system
No response
Xcode version information
No response
Swift Compiler version information
No response
Hi @Milanp24 thanks for reaching out. We currently do not support react native either via an SDK or a bridge. We do plan on having a react native SDK sometime in the near future so that developers like you don't have to create your own package.
One approach I can suggest is using your iOS app's AppDelegate
to set the push token like so -
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[Klaviyo setTokenWithDeviceToken:deviceToken];
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
// Store or use the device token as needed
NSLog(@"Device Token: %@", token);
}
I will be closing this out since this is not an issue with the SDK as it currently only is meant to be used from iOS native applications. If you have any suggestions on how we should build the react native package please don't hesitate to open a discussion on this repo. Further, you can also reach out to other developers in the Klaviyo community who may be similar implementation to your's.
Good luck!
Hi @Milanp24, just thought I'd bring your attention to version 2.5.0
just released, in which we added an overload you can use to set token with a plain string.