ios icon indicating copy to clipboard operation
ios copied to clipboard

Local Notification not working

Open martinop opened this issue 5 years ago • 8 comments

Bug report

Summary

When I receive a push notification in foreground mode, "messaging(). OnMessage" (firebase messaging) is triggered with the notification data but when trying to show the notification with PushNotificationIOS.localNotification or PushNotificationIOS.scheduleLocalNotification nothing happens, it works in the emulator but testing in a Iphone 11 not working

Environment info

react-native info output:

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 31.07 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.1 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.2 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

Library version: ^1.2.2

Steps to reproduce

  1. Receive a push notification in foreground
  2. Call localNotification or scheduleLocalNotification

Describe what you expected to happen:

  1. Receive a push notification in foreground
  2. Call localNotification or scheduleLocalNotification and be able to see the notification message

Reproducible sample code

martinop avatar Sep 08 '20 21:09 martinop

Im currently working on this topic and able to get local notification pushed with some slight tweak on Firebase Messaging. In the folder /node_modules/@react-native-firebase/messaging/ios/RNFBMessaging, file RNFBMessaging+UNUserNotificationCenter.m at method willPresentNotification

I did a replace from completionHandler(UNNotificationPresentationOptionNone); to completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);

Somehow, my app crashed when leaving them as per repo. Using "@react-native-firebase/messaging": "^7.8.4"

Also, I commented willPresentNotification at my AppDelegate.m.

TommyLeong avatar Sep 09 '20 07:09 TommyLeong

but are you sure is the same problem? I'm able to receive the notification, the problem is to display with localNotificationr or scheduleLocalNotification @TommyLeong

martinop avatar Sep 10 '20 17:09 martinop

Perhaps you could ignore my previous comment, I seems to have some setup issue hence that was my fixed earlier. However Im pretty sure localNotification is working on both Android and iOS (which I hv just tested yesterday). Perhaps the following will help you?

Dependencies

"@react-native-community/push-notification-ios": "^1.4.1",
"@react-native-firebase/messaging": "^7.8.4",
"react-native-push-notification": "^5.0.1",

iOS

messaging().onMessage(async remoteMessage => {
    PushNotificationIOS.presentLocalNotification({
      alertTitle: remoteMessage.notification.title,
      alertBody: remoteMessage.notification.body
    })
  });

Android

   PushNotification.localNotification({
         title: remoteMessage.notification.title,
         message: remoteMessage.notification.body
      })

TommyLeong avatar Sep 11 '20 03:09 TommyLeong

I have updated the libraries version but still not working for me :( were you able to test it on real device? @TommyLeong

my code:

const unsubscribe = messaging().onMessage(async e => {
if (Platform.OS === 'android') {
	PushNotification.localNotification({
		title: e.notification.title,
		message: e.notification.body,
		userInfo: e.data,
	});
} else {
	PushNotificationIOS.presentLocalNotification({
		alertTitle: e?.data?.notification?.title,
		alertBody: e?.data?.notification?.body,
		userInfo: e.data,
	});
}
});

martinop avatar Sep 15 '20 17:09 martinop

I'm experiencing the same situation. Were you able to come up with a solution?

Ayse-Erduran avatar Sep 29 '20 23:09 Ayse-Erduran

Unfortunately not :/

martinop avatar Sep 29 '20 23:09 martinop

@martinop putInsideAMethod(){ PushNotification.localNotification({ title: e.notification.title, message: e.notification.body, userInfo: e.data, }); }

const unsubscribe = messaging().onMessage(async e => { if (Platform.OS === 'android') {

putInsideAMethod()

} else { same });

SachinDodti avatar Oct 23 '20 06:10 SachinDodti

@martinop putInsideAMethod(){ PushNotification.localNotification({ title: e.notification.title, message: e.notification.body, userInfo: e.data, }); }

const unsubscribe = messaging().onMessage(async e => { if (Platform.OS === 'android') {

putInsideAMethod()

} else { same });

not work for me

anhdo9797 avatar May 14 '21 07:05 anhdo9797