Closed hhemmati81 closed 3 years ago
If I send a push notification with content available then I can get a custom local notification by calling it inside the Pushy.setNotificationListener.
Pushy.setNotificationListener(async data => {
PushNotification.localNotification({
title: data.title,
channelId: 'custom',
message: data.message,
bigText: data.message,
playSound: true, // (optional) default: true
soundName: 'ring.wav',
});
});
This however only works when the app is in the foreground or in the background. It opens the custom notification right after the pushy notification. When the app is closed only pushy notification pops up not the custom notification which tells me Pushy.setNotificationListener is not getting called since there is no headless js in iOS.
I saw another issue post on how to silence pushy notifications but I couldn't get it to work in the appdelegate.m maybe an outdated code?
// Handle silent push notifications
[pushy setNotificationHandler:^(NSDictionary *data, void (^completionHandler)(UIBackgroundFetchResult)) {
// Print notification payload data
NSLog(@"Received notification: %@", data);
// Custom logic...
// You must call this completion handler when you finish processing
// the notification (after fetching background data, if applicable)
completionHandler(UIBackgroundFetchResultNewData);
}];
I figured if I silence pushy notification banners from showing up then the only thing I have to figure out is how to get the custom localnotification to appear for when the app has been closed.
Hi @hhemmati81, Thanks for reaching out and creating this issue. We'd be glad to assist.
Unfortunately, as per the iOS docs, silent notifications (content_available: true
) will only wake up your app to execute code if it hasn't been swiped away / killed by the user:
However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
This is an Apple design decision, and applies to both native iOS apps with native notification listeners, as well as React Native iOS apps with JS notification listeners.
Therefore, there is no way to clear an existing notification that was previously received, if your app has been killed. We apologize for this inconvenience introduced by Apple.
I am trying to implement expiring notifications. I am using React Native Push Notification and React Native Push Notification iOS. In Android, I just pass the notification data from Pushy to localNotification in Pushy.setNotificationListener but iOS is not working. From what I have figured out so far is that I have to do this in the AppDelegate.m. My question is how do I pass the data from pushy to push notification ios in the AppDelegate?