Unable to receive push notification through expo-notifications in production build Android

Viewed 274

The expo push notifications through Firebase configuration was working well for last 1.5 months until 2 days ago, the production build stopped receiving any notifications. On further analysis of this issue, I found that the exponent push token was not being generated by the getExpoPushTokenAsync() method for android platform alone. IOS still works fine.

I haven’t touched the code regarding notifications for the last 1.5 months. Don’t know how to fix this as it is an important feature of the app. All the FCM configurations have been done properly. The notifications and expo token generation works in development though, when using the expo go app but just not in production.

const registerForPushNotificationsAsync = async () => {
let token;
if (Device.isDevice) {
  const { status: existingStatus } =
    await Notification.getPermissionsAsync();
  let finalStatus = existingStatus;
  if (existingStatus !== "granted") {
    const { status } = await Notification.requestPermissionsAsync();
    finalStatus = status;
  }
  if (finalStatus !== "granted") {
    return;
  }
  token = (await Notification.getExpoPushTokenAsync()).data;
}

if (Platform.OS === "android") {
  Notification.setNotificationChannelAsync("default", {
    name: "default",
    importance: Notification.AndroidImportance.MAX,
    vibrationPattern: [0, 250, 250, 250],
    lightColor: "#FF231F7C",
  });
}
return token; };

 useEffect(() => {
// method to check JWT token validity before making API call
let tokenValidity = checkJwtValidity(
  jwtToken,
  setIsLoggedIn,
  setjwtToken,
  setUser
);
if (tokenValidity) {
  registerForPushNotificationsAsync().then(async (token) => {
    // on receiving of token, making an api call to send to backend so they can push the notification to    the device using the token
    const response = await sendDeviceNotificationToken(jwtToken, token);
    console.log(response);
  });
}}, []);
1 Answers

Just added one line on my app/build.gradle.file and it started working.

implementation 'com.google.firebase:firebase-iid:17.0.2'
Related