Push Notifications are not working in iOS using Expo

Hi team, I am facing an issue with push notifications in Expo. Actually we are using Expo Push Notification service for Backend API’s and using Notifications listener in react native code of expo. It is working fine and able to receive notifications in Android but the same code is not working for iOS. One or two times I got the push notification in iOS, but it is not working as in Android. Can anyone please help us with your inputs asap.

Thank you in Advance.

Hi @bnuthalapati,

Can you put your Expo Client Side Code please.

This is my code which I wrote in my app login page in componentDidMount() lifecycle method:

async registerForPushNotificationsAsync() {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);

let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
  const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  finalStatus = status;
}
if (finalStatus !== 'granted') {
  return undefined;
}
let token = await Notifications.getExpoPushTokenAsync();
console.debug('token', token)
return token;

}

This is the code which I used to listen the push notifications whenever those are triggered.

componentDidMount() {
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}

_handleNotification = (notification) => {
console.debug(‘Notification’, notification)
if (notification.data.title && notification.data.body) {
if (Platform.OS == “ios”) {
const localnotification = {
title: notification.data.title,
body: notification.data.body,
// android: {
// sound: true,
// },
// ios: {
// sound: true,
// },
};
// let sendAfterFiveSeconds = Date.now();
// sendAfterFiveSeconds += 100;
// console.log(“local notification”,localnotification)
// const schedulingOptions = { time: sendAfterFiveSeconds };
Notifications.presentLocalNotificationAsync(
localnotification
);
}
}

Hey @bnuthalapati!

Here is a link to a Snack that implements Push Notifications. You should be able to run it on your own device and successfully receive push notifications. (Can send the notification with the Expo Push Notification Tool, or through the app itself)
Let me know if looking at this example helps you in figuring out what the issue is!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.