expo: [iOS] getExpoPushTokenAsync can't work on first time iOS . need restart ?

šŸ› Bug Report

I have install expo-notification to use on my Bare workflow app . On android it work as expected . How ever , on iOS (xcode 11) . the getExpoPushTokenAsync just hang on the first time opening app ( notification is allowed ) . The only way to get it work is restart the app ( kill app then re open ) . Any one know the root cause . Please share

Environment

Expo CLI 3.19.2 environment info:
    System:
      OS: macOS 10.15.3
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 13.13.0 - /usr/local/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.4 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.6 AI-192.7142.36.36.6392135
      Xcode: 11.4/11E146 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^37.0.8 => 37.0.8 
      react: 16.9.0 => 16.9.0 
      react-native: 0.61.4 => 0.61.4 
      react-navigation: ^4.2.2 => 4.2.2 
    npmGlobalPackages:
      expo-cli: 3.19.2

Steps to Reproduce

Open the app in iOS , log or show the push token . First time open app , request for notification allowed . No pushtoken . Debug show that getExpoPushTokenAsync hang .

Kill app then reopen . getExpoPushTokenAsync can get the push token and show as expected

Expected Behavior

Push token must be granted for the first time open app

RegisterPushToken code

import * as Notifications from "expo-notifications";
import Constants from "expo-constants";

export default async () => {

 await Notifications.requestPermissionsAsync();

  let experienceId;
  if (!Constants.manifest) {
    // Absence of the manifest means we're in bare workflow
    experienceId = "@redclouds/TappoMerchant";
  }
  const expoPushToken = await Notifications.getExpoPushTokenAsync({
    experienceId
  });

  console.log("expoPushToken.data", expoPushToken.data);
  __DEV__ && console.warn("ExponentPushToken", expoPushToken.data);

  return Promise.resolve(expoPushToken.data);
};

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Thank you all for reports of this problem. Frankly speaking the being run forever makes the most sense—there is no way another Promise would be run if you didn’t run it. I’ll take a look at it as soon as possible, I’ve also heard @tsapeta has reproduced it—the Promise didn’t resolve immediately and only after a long while the system permissions dialog showed up—maybe it’s some kind of iOS bug? I’ll let you know when I find out!

Thanks for the update @sjchmiela, in my case the issue is that Notifications.getDevicePushTokenAsync does not throw any error at all(which is obviously there) so no chance to figure out the reason of fail, so please check that it throws when something goes wrong…