react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
745 stars 285 forks source link

How can I prevent to receive notification when app in foreground? #344

Closed AlanWen2016 closed 2 years ago

AlanWen2016 commented 2 years ago

PM doesn' t want to get notification when app in foreground.How can I prevent to receive notification when app in foreground?

Wimmind commented 2 years ago

@AlanWen2016 send local notification, when the remote came

tavour-frank commented 2 years ago

you can change the behavior in your app delegate:

// Called when a notification is delivered to a foreground app.
  -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
  {
    completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
  }

https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter?language=objc

sounds like you'll want UNNotificationPresentationOptionNone ( other options documented here)