Hi everyone,
I’m facing an issue with push notifications in my Ionic 7 app using Capacitor 5. The push notifications are working perfectly fine in development mode, but when I install the app from the App Store in production mode, the push notifications don’t seem to work.
I’ve followed all the necessary steps for setting up push notifications, including configuring the plugin, obtaining APNs/FCM keys, and handling the token registration. However, I’m not receiving any push notifications on production installs.
Here’s a snippet of the code I’m using to handle the token registration in my iOS AppDelegate:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().token(completion: { (token, error) in
if let error = error {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
} else if let token = token {
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
}
})
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
Has anyone else encountered this problem? Are there any specific Info.plist entries or other settings that might need to be adjusted for push notifications to work in production mode?
The following code is the registerNotifications in my side, as I also try to use @capacitor-community/fcm to get the token, but that doesn’t work as expected.
registerNotifications = async () => {
let permStatus = await PushNotifications.checkPermissions();
if (permStatus.receive === 'prompt') {
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == 'granted') {
PushNotifications.addListener('registration', async ({ value }) => {
let token = value; // Push token for Android
// Get FCM token instead the APN one returned by Capacitor
if (Capacitor.getPlatform() === 'ios') {
const { token: fcm_token } = await FCM.getToken();
token = fcm_token;
}
// Work with FCM_TOKEN
localStorage.setItem(storageKeys.pushNotificationToken, token);
console.info('Registration token: ', value);
});
} else {
// No permission for push granted
localStorage.setItem(storageKeys.pushNotificationToken, generateUUID());
throw new Error('User denied permissions!');
}
});
}
await PushNotifications.register();
};
Any help or insights would be greatly appreciated. Thanks in advance!