React-native-fcm: Can't receive notification on background and some other problems [IOS]

Created on 21 Sep 2016  路  45Comments  路  Source: evollu/react-native-fcm

Hey,

陌 did everything but i still can't receive any notifications when my app is on background. Here is an example request:

{
  "to": "XXXX",
  "content_available": true,
  "priority": "high",
  "notification": {
     "title": "Please",
     "body": "Work"
  }
}

Other than that, i can receive notifications on my ios 9 iphone on foreground, but i don't receive anything on my ios 10 iphone.

I found something like this: https://firebase.google.com/docs/cloud-messaging/ios/receive

And there is one more thing i didn't understand, even when i don't allow notifications, or disable from settings, getFCMToken() function still returns a token, and i can send notifications.

So i am not sure if this library or FCM is stable, or is it a waste of time trying to adapt it atm.

All 45 comments

@evollu Any clue?

as the link shows, you need to define couple more handlers for iOS 10. I'm working on it.
regarding the second issue, FCM also has another tunnel for data messaging, which is not relying on apple push notification. If you disable notification you won't see any banner or badges but data messaging still works

@evollu thanks for the reply! But i couldn't make the notification appear when the app is on the background, even when the permission is given. You can see my example request above, i get a success response but no notification.

can you add break point in notification handlers in AppDelegate.m and see if they gets triggered?

Is there a fix for this?

@Brockify we have couple people have it working properly so it is more about debugging rather than fixing

@evollu what can I do to get started on fixing it?

try add break point in notification handlers in AppDelegate.m and see if they gets triggered?
and probably post your appdelegate.m

@evollu I logged in my- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
[[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification];
handler(UIBackgroundFetchResultNewData);
}
and I only get the log if the app is active and is in the foreground. If its in the background it gets this error:

Disconnected from FCM
and then a bunch of random errors like
Socket is not connected
2016-09-27 15:46:10.325023[1997:531213] [] nw_socket_get_input_frames recvmsg(fd 21, 1024 bytes): [57] Socket is not connected
2016-09-27 15:46:10.330341[1997:531679] [] nw_connection_write_close 64 Connection is not ready, sending error callback

Anything specifically I could send you @evollu

@evollu I added in all the new things and now on ios 10 my devices don't get a notification at all even when its running

can you share a public project with this issue so I can debug?

@evollu I believe I got it :). Thanks +1

Found out GCM is getting received now, just my web socket is closing whenever I lock the screen.

socket closing is expected. FCM socket is only used for data notification. push notification doesn't go through that channel

Hi,
I'm having the same problem with push notifications. It's work OK when app is in foreground, but when app is in the background or completely removed from memory I do not get any push notifications. I've tried to resolve problem but without success.

My request:
{ "priority" : "high", "content_available" : true, "data": { "score": "5x1", "time": "15:10" }, "notification": { "title": "Portugal vs. Denmark", "body": "5 to 1", }, "to" : "xxxxxxx" }

I'm using xcode8(deployment target is 8.0), react native v0.34.1 and react-native-fcm v2.2.0.
Also, I've set all settings how it's described in ReadMe.
Everything works fine on Android but on iOS I have problem that I've described.

@evollu
does this works for you i.e do you get notifications when app is in background or closed? And if it does, do you have some example how did you done it
Thanks for your help

Best regards

have you requested permission?

@evollu Hey do you know why I have it getting a gcm and it should trigger and update from my database but the update from my database never goes through when the phone is locked...

Hi,
yes,
and I get permission popup window when app starts for the first time.

@Brockify The notification only goes to JS when app is running or resumed to foreground. what are you trying to achieve?

@sumzer can you add break points to all iOS handler in appDelegate.m and see what is triggered when you send a message when app is in background?

@evollu the user has the phone locked, but I want to be able to start playing music from spotify when the user gets a gcm.

@evollu
I can try.

@Brockify wow. I suggest write native code to achieve that.

@evollu I currenly have native code for playing music and what not, but the issue I have now is getting music to start playing when it is in the background. When it is running everything is good, was hoping you might have some insight.

@Brockify ios or android?

@evollu only on iOS, on android everything works fine.

can you check if getRemoteNotication:withCompletionhandler is called?
if you are using example code in readme, you need to move this method outside the if condition

@evollu maybe that is the issue? The only two delegate methods that I use are
didReceiveNotificationResponse
didReceiveRemoteNotification

@evollu
I've put some break points on all iOS handler from readme (didReceiveRemoteNotification ...), but none of them is never fired.

@evollu @sumzer was just checking mine and mine don't get fired ever either.

@Brockify use the one with completeHandler. check readme Q&A to see the difference

@evollu here is my code for receiving in the background. It does receive it, but for some reason the music doesn't start playing nor does my UI get updated when phone is locked.

did javascript function get called?

@evollu yes it did

@evollu When i add a break point to didReceiveRemoteNotification it doesn't get triggered, however if i move the method outside from the if else block it gets triggered.

ios 9.3.2
xcode 8.0

then keep it outside i will update doc

I have this same problem, I am able to receive foreground notificaitons, but not background ones on IOS. I've requested all the permissions described. This works fine on Android.

Any additional updates?

it is usually due to APN set up or notification permissions.

I have push notifications, Keychain Sharing and Background Modes (Remote Notifications) all set up and enabled on XCode and Push Notifications set up on Apple Developer. I've also uploaded my certs to Firebase.

Any other places to look?

I am using the simulator, it appears you can't do remote push notifications on the simulator? http://stackoverflow.com/questions/21741259/push-notifications-in-mavericks-ios-simulator

right

@Brockify were you able to find a solution to this issue? I'm unable to see any notifications when the app is not in the foreground. (iOS only)

Also doubled checked APN certs and they are good.

react-native: 0.38.1
react-native-fcm: 2.5.6

@jnrepo Enable Push Notifications in Capabilities and @evollu Please add enable Push Notifications in Capabilities tab in Xcode project. There seems to be a lot of configuration to get push notifications working but we tend to forget the most basic things. :)

thanks @arunshan

Was this page helpful?
0 / 5 - 0 ratings