Notification Error in ios [Error: Another async call to this method is in progress. Await the first Promise.]

Please provide the following:

  1. SDK Version: “^42.0.0”,
  2. Platforms(Android/iOS/web/all): iOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hello,

[expo-notifications] Error encountered while updating server registration with latest device push token., [Error: Another async call to this method is in progress. Await the first Promise.]

This error often occurs in expo app. And always occurs in build ios app.

Using the following code:

async function registerForPushNotificationsAsync() {
  let token
  if (Constants.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync()
    let finalStatus = existingStatus
    if (existingStatus !== 'granted') {
      const { status } = await Notifications.requestPermissionsAsync({
        ios: {
          allowAlert: true,
          allowBadge: true,
          allowSound: true,
          allowAnnouncements: true,
        },
      })
      finalStatus = status
    }
    if (finalStatus !== 'granted') {
      console.log('noti cancel')
      return
    }
    // token = (await Notifications.getExpoPushTokenAsync()).data

    try {
      await Notifications.getExpoPushTokenAsync().then((res) => {
        console.log('getExpoPUshTokenAsync >> ', res)
        token = res.data
      })
    } catch (err) {
      console.log('getExpoPushTokenAsync error >> ', err)
    }
  } else {
    Alert.alert(
    'Must use physical device for Push Notifications'
    )
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
    })
  }

  return token
}

I have received a new credential, but I am still getting the error.

I installed “expo-notifications”: “~0.12.3”

await Notifications.getExpoPushTokenAsync().then((res) => {
        console.log('getExpoPUshTokenAsync >> ', res)
        token = res.data
      })

You’re using both async/await syntax with then, which do essentially the same thing

I suggest using the example code from the docs

1 Like

Actually I used docs code.

  token = (await Notifications.getExpoPushTokenAsync()).data

But, It occurs below error :cry:

[expo-notifications] Error encountered while updating server registration with latest device push token., [Error: Another async call to this method is in progress. Await the first Promise.]
at node_modules/expo-notifications/build/DevicePushTokenAutoRegistration.fx.js:54:20 in __handlePersistedRegistrationInfoAsync
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

[Unhandled promise rejection: Error: Another async call to this method is in progress. Await the first Promise.]
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-notifications/build/getDevicePushTokenAsync.js:4:15 in getDevicePushTokenAsync
at node_modules/expo-notifications/build/getDevicePushTokenAsync.js:4:15 in getDevicePushTokenAsync
at node_modules/expo-notifications/build/DevicePushTokenAutoRegistration.fx.js:31:7 in __handlePersistedRegistrationInfoAsync
at node_modules/expo-notifications/build/DevicePushTokenAutoRegistration.fx.js:31:7 in __handlePersistedRegistrationInfoAsync
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

Hey @useb-official can you provide a Snack or public github repo that we can use to test this locally? It’s hard to deduce what’s going wrong without being able to see/run all the code.

Cheers,
Adam

Umm… It’s our company real app code. So, I have to ask my boss.

And That error show when app start. Before call getExpoPushTokenAsync

Can I create a private repository and invite you to check it out?

Perhaps I solved the error.(I’m not sure :cry:)

I used expo-file-dl library. And this library use expo-notification.
So, I think that make conflict.