0
votes

Why I'm not receive notification not received in background???

It's my first experience when I work with Push Notifications. I read the documentation and follow for guide from Google Firebase Doc. Also I implement code from firebase/quickstart-ios. After that I created console on firebase service, upload my certificate and successfully send message which I receive as in Foreground so in Backround too.

But when I change console which I taken from backend developer, my app stopped take push notification in Background mode.

What I'm doing:

  • In capabilities Push Notification set to "ON"
  • In capabilities Background Mode enable "Background fetch", "Remote notification"
  • content_available set to "1"
  • Sending message Priority set to "High"

I can't understand why app stopped receive notification in Background if it working well before.

I also read the same question on stackoverflow, but didn't find the solution of my problem.

Please, help to sort out this problem!

UPDATE:

Actually I didn't receive any notification as in Background so in Foreground. The reason was that I accepted receive notification when I install my app with GoogleService-Info.list from first console. So, if you change the console, of course you change the GoogleService-Info.list, and you should again to accept receive notification!!! If you don't to accept, didReceiveRemoteNotification will not call!

2
That's odd. content_available shouldn't be set to 1, it should be set to true when using FCM. Can you try it out? If it still doesn't work. Can you post a string structure of your payload? - AL.
Thank you for you replay! I'm changed value to "true", and still notification not to received. So this is response in Foreground %@ [AnyHashable("notification"): { badge = 1; body = New15; e = 1; sound = default; sound2 = default; title = Title; } Does you mean this? - Roman Romanenko
I was referring to the payload coming from your app server. :) - AL.
It's the same as sting above: { 'content-available': '1', aps: { badge: 1, body: 'New15,' sound = enable, title = Title} }. I'm sure that property filled right. As I said, at first console.firebase everything works fine, but at the second not. - Roman Romanenko
Are you testing this with the firebase console or are push notifications being sent from an FCM server? AFAIK the console has limitations. It would be better to test with CURL and adjust your payload to have a notification and data payload, depending on how you want FCM to handle the notifications - Brien Crean

2 Answers

0
votes

You haven't added any code so there might be a few things to consider:

Ensure that you have fetchCompletionHandler defined in order for content-available: true to be able to wake the app when a push notification is received.

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                   fetchCompletionHandler completionHandler:{ @escaping (UIBackgroundFetchResult) -> Void)
fetchCompletionHandler(UIBackgroundFetchResultNewData);
}

FCM handles notifications differently depending on what is contained in the push notification payload. Try using a push notification with a data only payload and a notification only payload, experiment and see what happens.

{
  "to":"push_token",
    "content_available": true,
    "priority": "high",
    "notification": {
      "title": "New Message",
      "message": "Bob sent you a message",
    },
    "data": {
      "title": "New Message",
      "message": "Bob sent you a message",
    }
}

Use this CURL Command instead of using the firebase console to test sending push notifications

curl -X POST --header "Authorization: key=APIKEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "@push_payload.json"
0
votes

The reason was that I accepted receive notification when I install my app with GoogleService-Info.list from first console. So, if you change the console, of course you change the GoogleService-Info.list, and you should again to accept receive notification!!! If you don't to accept, didReceiveRemoteNotification will not call!

P.S. In my variant I'm implement notification with swizzling. If you chose the same way, be sure that in your Info.plist file you have property FirebaseAppDelegateProxyEnabled which value setup as YES