Notifications API not working since expo client update

Hi Guys,

My app was working fine last Tuesday, but today it is failing when it has to use de Notifications API.

I tried the Snack that is shared in de documentation and it seems to be failing too.

I realize that the expo client has been updated, adn I do not know if this is the root of the issue.
¿is there additional configuration that I had to do since the last update of expo?

this is my code:

class NotificationService extends ApiService {
constructor() {
super();
Notifications.addListener(this.onNotification);
}
async registerForPushNotificationsAsync(userToken) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS,
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined
if (existingStatus !== ‘granted’) {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== ‘granted’) {
return;
}
if (Platform.OS === ‘android’) {
Notifications.createChannelAndroidAsync(‘updates’, {
name: ‘updates’,
priority: ‘max’,
vibrate: [0, 250, 250, 250],
});
}
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
//TODO delete this console log
console.log(‘Expo push token’, token);
const reqBody = JSON.stringify({
deviceToken: token,
});
// PATCH the token to backend server from where you can retrieve it to send push notifications.
userService.modifyUser(reqBody, userToken);
}

onNotification(notification) {
console.log(‘notification:’, notification);
}
}

Appreciate your reply.

GC

I can’t help but this is happening to me as well. This is the second expo update in a matter of weeks and it’s crashed my app both times…making it very frustrating to use expo at all.

i think the issue is with your code.

i opened this app up on my phone: lonely cheese - Snack
then i went to the logs section and copied the token
then i went to Push Notification Tool — Expo and pasted the token
i filled in some content and press send notification. you may not receive it immediately (apple does not guarantee that and so neither can we, naturally), so entertain yourself by changing the fields and then trying again.

i also don’t know what you mean about this being the second expo update in the matter of weeks. we released sdk37 and this is the only update that we have done since sdk 36 was released in the beginning of december. sorry that you are having a bad experience!

@notbrent, thank you for your reply.
I tried the snak you send and it is not working in my Android phone neither. It is not printing the token in logs.

It stop executing after Notifications.getExpoPushTokenAsync, I put a console log after this line and is not printing. It has the same behavior than my code.

What could it be generating this behavior?

hey @plataforma - i think snack is behaving a little strange on android right now. copy the project to your local machine and try it, it should work as expected

@notbrent,
I ran my code on iPhone and it worked perfectly.
I followed your recommendation and ran the snak locally but it has the same behavior. It stops the code. No token received.
I think it could be a problem with the new version of the Expo Client for Android. ¿what do you think?

Update: I generated the apk and install it in my Android phone and my code works fine.

Hi.

Im have the same problem with my project. The push notifications dont work.
Im try online with this example and have the same problem test notify - Snack

I am calmer knowing that it is a general problem although I lost the whole afternoon believing it was my mistake

so you ran this code using expo-cli and you are unable to get the push token from your android device?

Yes, and for example this dont work: lonely cheese - Snack

In this code:
console.log(“Step 1”);
let token = await Notifications.getExpoPushTokenAsync();
console.log(“Step 2”);
console.log(token);
this.setState({expoPushToken: token});

Only show in console “Step 1”
Step 2 never show in console. And dont show errors

UPDATE: Im font this example from charliecruzanExpo Team and dont work.

In console dont show errors

@notbrent - gotcha could be my error in regards to updates. But about 3 weeks ago expo was working fine - then the green box indicating a newer version was available started popping up and my app no longer worked. Had to uninstall and reinstall expo-cli. Everything worked fine for a few weeks again until today the green box is back showing a new version and code no longer works.

@notbrent
I created a new project with expo init my-new-project , copied the code and ran in Android Expo Client having the same result.

If they really aren’t working, yesterday afternoon and today morning I tried to see if it was my mistake but I took out a test project that I generated 2 weeks ago and it doesn’t work either.

Additionally, from this project I had the generated APK and this YES generates the TOKEN for the notification, but if we compile the project TODAY it does NOT generate a token.

If you need something to find the problem and I can help you, count on me, but so far I know that my code arrives at the function

let token = await Notifications.getExpoPushTokenAsync();

something happens here and never returns the token

Hey all, this issue has also been reported on Github — let me redirect the discussion there. We have reproduced the problem and will work on a fix. :slightly_smiling_face:

@sjchmiela
I see that you guys already closed the issue in github so I can’t comment anymore.
I tried the test that @notbrent suggested. You can see the code here: GitHub - germancardenasm/expoPushToken

But I am getting the following error. Could you please help me to see what is the error I am doing?

[Unhandled promise rejection: Error: Couldn’t get GCM token on device.]

  • node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:99:50 in fn
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:274:30 in invoke
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:135:28 in invoke
  • node_modules/regenerator-runtime/runtime.js:145:19 in PromiseImpl.resolve.then$argument_0
  • node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  • node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
  • [native code]:null in callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
  • [native code]:null in flushedQueue
  • [native code]:null in invokeCallbackAndReturnFlushedQueue

Im have the same problem. In GitHub is close, but im have the problem.

Try expo upgrade and dont work.

I don’t know if we need to wait for the changes to spread or something.

can you provide more information about what contect this happening in? ios, android? @plataforma you should delete that repository asap because it includes some sensitive information

i ran the project you shared @plataforma and it worked as expected - i got the push token

the error you are seeing corresponds to this: Expo 35, Push Notifications not working on android "Error: Couldn't get GCM token for device" · Issue #5900 · expo/expo · GitHub - tldr: sign in to expo-cli, run expo start, and it should be resolved.

this is not a great error message to receive in this context so i can understand the confusion!

@notbrent im have the same problem. Im was login:

[Unhandled promise rejection: Error: Couldn’t get GCM token on device.]

  • node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:99:50 in fn
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:274:30 in invoke
  • node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  • node_modules/regenerator-runtime/runtime.js:135:28 in invoke
  • node_modules/regenerator-runtime/runtime.js:145:19 in PromiseImpl.resolve.then$argument_0
  • node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  • node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
  • [native code]:null in callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
  • [native code]:null in flushedQueue
  • [native code]:null in invokeCallbackAndReturnFlushedQueue

› Press a to run on Android device/emulator, or i to run on iOS simulator, or w to run on web.
› Press c to show info on connecting new devices.
› Press d to open DevTools in the default web browser.
› Press shift-d to disable automatically opening DevTools at startup.
› Press e to send an app link with email.
› Press p to toggle production mode. (current mode: development)
› Press r to restart bundler, or shift-r to restart and clear cache.
› Press s to sign out. (Signed in as @casoft.)

@notbrent sorry for write and write…

If you test your example: lonely cheese - Snack

Dont work in this moment. Im think a step is needed so that everything is solved, but the truth I do not find missing

Thanks