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.

Can't get IOS notifications push token

See original GitHub issue

Summary

When calling getDevicePushTokenAsync or getExpoPushTokenAsync on an ios device, The promise never resolved and never throw.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

42

Environment

expo-env-info 1.0.2 environment info: System: OS: macOS 11.5.2 Shell: 5.8 - /bin/zsh Binaries: Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node Yarn: 1.22.11 - /opt/homebrew/bin/yarn npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm Watchman: 2022.01.31.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.2 - /Users/thibaultfischer/.rbenv/shims/pod SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 Android SDK: API Levels: 30, 31 Build Tools: 28.0.3, 29.0.2, 31.0.0 System Images: android-31 | Google APIs ARM 64 v8a, android-32 | Google Play ARM 64 v8a IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7678000 Xcode: 13.0/13A233 - /usr/bin/xcodebuild npmPackages: babel-preset-expo: 8.3.0 => 8.3.0 expo: ^42.0.0 => 42.0.5 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 Expo Workflow: bare

Reproducible demo

export const registerForPushNotificationsAsync = async () => { try { if (Constants.isDevice) { const status = await getNotificationsPermissionStatus(); if (status !== Permissions.PermissionStatus.GRANTED) { return; } const token = await Notifications.getExpoPushTokenAsync(); return token.data; } } catch (err) {

Here we never go in the catch and we never reach the “return token.data” line

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

5reactions
thibaultfischercommented, Jun 7, 2022

Ok, found the problem : We are using Intercom react native library, and setting it up we added this line : image

But now the didRegisterForRemoteNotificationsWithDeviceToken is not returning anything, so the expo getDevicePushTokenAsync never resolves…

The solution : If you are using a third party library that asks you to implement something in didRegisterForRemoteNotificationsWithDeviceToken method, make sure to return to keep expo notifications working : return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; image

0reactions
simon-tannaicommented, Oct 7, 2022

I got the same issue than @thibaultfischer: Intercom react library seems to have an issue with notification token. The fix proposed by @thibaultfischer is working fine: In the file ios/MyApp/AppDelegate.m, I replaced:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [IntercomModule setDeviceToken:deviceToken];
}

By:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [IntercomModule setDeviceToken:deviceToken];
    return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

Then, I updated the getExpoPushTokenAsync() params to add the experienceId and applicationId:

import { applicationId } from 'expo-application';

[...]

  const { data: expoPushToken } = await Notifications.getExpoPushTokenAsync({
    experienceId: '@my_company/my-project',
    applicationId,
    development: 'dev' === Constants.manifest.extra.ENVIRONMENT,
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not receiving push device token in… | Apple Developer Forums
Hi there, I'm seeing weird behavior when trying to register for push notifications in macOS development builds for any of my apps
Read more >
Why is my device not receiving push notifications on iOS?
The token field is empty. Make sure the install date you see in the debug tool makes sense and check if notifications are...
Read more >
Get device token for push notification - ios - Stack Overflow
1) Enable APNS (Apple Push Notification Service) for both Developer Certification and Distribute Certification, then redownload those two file.
Read more >
Push Notification Troubleshooting for iOS - Braze
If the push certificate you uploaded in the dashboard is not the same one in the provisioning profile that your app was built...
Read more >
Can't receive push notifications through Zendesk Messaging ...
... get push notifications working through the messaging SDK on ios but ... ZDKPushNotifications is registering the push notification token
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