klaviyo / klaviyo-swift-sdk

Swift SDK for integrating Klaviyo’s push notifications, event tracking, and user profile management into iOS applications.
https://www.klaviyo.com/mobile-push-marketing
MIT License
12 stars 11 forks source link

Unable to set push token in React Native Project #113

Closed Milanp24 closed 11 months ago

Milanp24 commented 11 months ago

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

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

ajaysubra commented 11 months ago

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!

evan-masseau commented 8 months ago

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.