react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

createLocalNotification() on iOS won't display notification (show_in_foreground: true set)

Open DavideValdo opened this issue 9 years ago • 19 comments

This code works correctly on Android:

   firebase.database().ref('gifts').on('child_added', (snap) => {
      gift = snap.val();

      firebase.messaging().createLocalNotification({
        body: gift.name,
        show_in_foreground: true
      })
    })

On iOS, i just get this warning from React Native: messaging_notification_received with no listeners registered.

.onMessage(message) works fine

When I build the .xcworkspace, I can get this from XCode's console:

2017-07-02 18:47:52.015430+0200 appname[1081:1020773] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.

EDIT: Added flag to plist, message disappeared but nothing changes:

Also i noticed:

2017-07-02 19:32:36.452674+0200 app[1086:1026966] [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

2017-07-02 19:32:36.453 app[1086] <Notice> [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO

Still, notifications sent by triggering FCM via cURL just work when app is in the background.

DavideValdo avatar Jul 02 '17 17:07 DavideValdo

I am getting the same error.

EDİT: i solved the error. I have forgotten to turn push notification status on

Make sure you give permissions like below screen shot 2017-07-08 at 13 00 46

hamzauzumcu avatar Jul 08 '17 09:07 hamzauzumcu

@DavideValdo The fact that you're getting messaging_notification_received as an error means that the notification is triggering, it's just not displaying via the OS. Try adding a title parameter to your notification and see whether this works?

As an aside, show_in_foreground is Android specific functionality and should only be required for remote notifications. It's also something we're considering removing from RNFirebase Messaging but before we do, we'll explain how to do something similar in your own code.

chrisbianca avatar Jul 10 '17 07:07 chrisbianca

@DavideValdo I'm going to assume that this is no longer an issue and close it. Please let me know if that is not the case.

chrisbianca avatar Jul 19 '17 15:07 chrisbianca

I'm getting the same error from React Native on iOS:

Sending `messaging_notification_received` with no listeners registered.

The local message I sent is like this:

{
  body: 'My Notification Message',
  id: '1503311359441',
  local_notification: true,
  show_in_foreground: true,
  title: 'My Notification Title',
  _notificationType: 'local_notification',
}

It works fine on Android, and message from remote works on iOS too.

leethree avatar Aug 21 '17 10:08 leethree

I has the same issue on IOS. On android working fine. I'm using "react-native-firebase": "2.1.4","react": "16.0.0-alpha.12" and "react-native": "0.47.2",

Shinichi52 avatar Sep 14 '17 08:09 Shinichi52

@Shinichi52 What is the solution??? Help please...

sseyha avatar Nov 10 '17 09:11 sseyha

#595

DavideValdo avatar Nov 15 '17 08:11 DavideValdo

A quick hack to this issue adding below flag during create local notification

if([details objectForKey:@"show_in_foreground"] != nil) {
    if([(NSNumber *)details[@"show_in_foreground"] boolValue] == YES) {
        [content setValue:@YES forKeyPath:@"shouldAlwaysAlertWhileAppIsForeground"];
    }
}

You may refer to full code in this branch ios-foreground-notif

kkkevinnn avatar Nov 16 '17 09:11 kkkevinnn

@hisokakei Your trick working well, it should be merged to new version. Thank you

thienlhh avatar Dec 21 '17 10:12 thienlhh

where is it documented?

victorsferreira avatar Jan 13 '18 00:01 victorsferreira

@sseyha i'm using react-native-fcm. it's working fine

Shinichi52 avatar Jan 18 '18 02:01 Shinichi52

@hisokakei I've only added that flag after doing an initial build. Would I need to relink the plugin?

robert-stevens avatar Jan 18 '18 14:01 robert-stevens

@uppercase-army you need to rebuild your app to make it work as it changed native code.

The change is merged to master too. You may upgrade your library to master

kkkevinnn avatar Jan 19 '18 11:01 kkkevinnn

The version I'm using contains the code that @hisokakei posted, still my local notification wont show up when in foreground, any ideas?

this is my notification object:

messaging.createLocalNotification({
        body: 'message',
        title: 'title',
        local_notification: true,
        priority: 'high',
        show_in_foreground: true
      });

escobar5 avatar Feb 23 '18 20:02 escobar5

+1

ferprez avatar Feb 27 '18 15:02 ferprez

+1 still struggling

vulkandev avatar Feb 27 '18 18:02 vulkandev

Me too :/ Any ideas? It works well on Android, but not on iOS

WaldoJeffers avatar Mar 01 '18 09:03 WaldoJeffers

Guys please refer to https://github.com/invertase/react-native-firebase/issues/595

As it stands, we're re-working the entire side of messaging.

Ehesp avatar Mar 01 '18 11:03 Ehesp

Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!

Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1

If you have any comments and suggestions or want to report an issue, come find us on Discord

chrisbianca avatar Mar 20 '18 09:03 chrisbianca