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);
}
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 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.
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.
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
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.
@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.
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
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
App.js:80:40 in AuthLoadingScreen#registerForPushNotificationsAsync
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.)