question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How is setupAPN() supposed to get the deviceToken?

See original GitHub issue

I see that the library includes setupAPN(deviceToken). How is the deviceToken supposed to find its way into the JS environment?

It’s not an issue because you can just add [Intercom setDeviceToken:deviceToken]; but wanted to know if there was an alternative way or if it’s there for API parity.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jplethiercommented, Jul 7, 2016

@ryankask I am using this flow too after the login, but before the login I have a UnidentifiedUser registered, and after login, seems that intercom is not setting the push token for the logged user.

This flows worked nicely for you?

0reactions
javiercrcommented, Jan 18, 2017

I think @rogchap is right. If you use react-native-push-notification (based in PushNotificationIOS) to register for remote notifications, and later use the resulting token to call setupAPN, you will probably run into problems as the encoding from String to NSData doesn’t seem to match the encoding on PushNotificationIOS:

+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  NSMutableString *hexString = [NSMutableString string];
  NSUInteger deviceTokenLength = deviceToken.length;
  const unsigned char *bytes = deviceToken.bytes;
  for (NSUInteger i = 0; i < deviceTokenLength; i++) {
    [hexString appendFormat:@"%02x", bytes[i]];
  }
  [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationsRegistered
                                                      object:self
                                                    userInfo:@{@"deviceToken" : [hexString copy]}];
}

As @rogchap suggested, if you call [Intercom setDeviceToken:deviceToken] directly from didRegisterForRemoteNotificationsWithDeviceToken it seems to work because it avoids the encoding problem. However this solution is not ideal, as in our case we would prefer to set the token (call setupAPN after the user logs in), while keeping the registration for the token handed by PushNotificationIOS (before the login).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Registering Your App with APNs - Apple Developer
You register your app and receive your device token each time your app launches using Apple-provided APIs. The registration process is similar across...
Read more >
Not getting device token of device for APNS? - Stack Overflow
Now my problem is when i install same app for other device, the following methods could not work. application:(UIApplication *)app ...
Read more >
Apple Push Notification Device Tokens - NSHipster
In order for its to be used to send push notifications, it needs to be sent from the client to the server. The...
Read more >
Correctly capture iOS 13 Device Token in Xamarin | by Kevin Le
To receive the Device Token, an app must register with APNs. ... the following line is returned by the toString() method in Xamarin...
Read more >
Sending Notifications with APNs & FCM - Expo Documentation
Now that you have your native device token, we can start to implement our servers. ... and we're just going to cover the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found