Closed victoravr closed 5 months ago
Hello, @victoravr 👋. Hoping to get some clarity around the behavior that you're reporting in this issue to make sure it's not expected. If the app is in the foreground state, then notifications are not displayed when received (see here). But are you saying that the onNotificationReceivedInForeground()
is not being triggered at all on iOS? Is this happening when the app is being booted up for the first time (or any time after being completely killed/shut down)?
@victoravr, we're able to reproduce this on our side and are investigating the root cause further. Labeling this as a bug for now.
Hi @victoravr - I am trying to look into this. Can I ask if you are seeing this behavior on actual iOS device as well? When it comes to push notifications, we are still seeing that simulators do not handle these use cases correctly.
Hi @victoravr - I am trying to look into this. Can I ask if you are seeing this behavior on actual iOS device as well? When it comes to push notifications, we are still seeing that simulators do not handle these use cases correctly.
Yes, I've seen this behavior on the actual iOS device as well during my testing.
Hi @victoravr, I am still working on a way to consistently reproduce this on an actual device. I can definitely confirm that, I am seeing this behavior on simulator, but they seem to resolve on an actual iOS device. Here is a log of my Xcode logs
On simulator, I find that using the simctl
command has been effective in simulating a foreground PN:
// apns.json
{
"aps" : {
"alert" : {
"title" : "Title",
"body" : "Body"
}
}
}
$ xcrun simctl push booted <bundle-identifier> ./apns.json
When testing on real devices, I have definitely seen instances where console logging stops working, could you please make sure this isn't what's happening? It could be helpful if you can provide some full logs from your iOS device with some of the other Amplify Push Notification APIs exercise as well - so we can try and trace down any patterns.
E.g. on a bare RN app:
useEffect(() => {
console.log('adding listeners');
const backgroundNotificationListener = onNotificationReceivedInBackground(
notification => {
console.log(
`Got a new backgroundNotification: ${JSON.stringify(notification)}`,
);
},
);
const foregroundNotificationListener = onNotificationReceivedInForeground(
notification => {
console.log(
`Got a new foregroundNotification: ${JSON.stringify(notification)}`,
);
},
);
const notificationOpenedListener = onNotificationOpened(notification => {
console.log(`Opened a notification: ${JSON.stringify(notification)}`);
});
const tokenReceivedListener = onTokenReceived(token => {
console.log(`Got a new token: ${token}`);
});
return () => {
backgroundNotificationListener.remove();
foregroundNotificationListener.remove();
notificationOpenedListener.remove();
tokenReceivedListener.remove();
};
}, []);
Hi @victoravr, I am still working on a way to consistently reproduce this on an actual device. I can definitely confirm that, I am seeing this behavior on simulator, but they seem to resolve on an actual iOS device.
Hi @cshfang, Yes, you are right. Just tested APNS push notification on the physical iOS device and it's working. Is there a way to fix it for iOS simulator? Thanks!
Hey @victoravr. It's good to hear that it's working for you! As mentioned, you can use simctl
locally to test the functionality on simulator but, unfortunately, Push Notifications on iOS simulator is still not quite at parity with the real thing. This is a limitation that Apple has been making strides in recent OS updates to overcome but is still not quite there.
Given that you are able to verify now that this is working on a physical device, can we consider this issue resolved?
@victoravr, appreciate your confirmations and follow ups here after @cshfang was able to root cause this. I'll close this issue out and remove the bug
label since there's no issue on the Amplify side of things.
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Push Notifications
Amplify Version
v6
Amplify Categories
notifications
Backend
CDK
Environment information
Describe the bug
onNotificationReceivedInForeground from aws-amplify/push-notifications is not triggered when app is in Foreground. Background notifications are OK.
Expected behavior
onNotificationReceivedInForeground from aws-amplify/push-notifications is triggered.
Reproduction steps
Code Snippet
App.tsx
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
iPhone 15 Pro Simulator
Mobile Operating System
iOS 17.4
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response