Firebase silent notification does not start up a closed iOS app
J

1

8

Can FCM silent notification start up a closed iOS app?

Request Type: POST

Request URL: https://fcm.googleapis.com/fcm/send

Request Headers:

Authorization -> key=MY_KEY

Content-Type -> application/json

Request Body:

{
  "to": "/topics/my_topic",
  "content_available": true,
  "data": {
    "contentAvailable": 1
  },
  "priority": 10
}

However, this payload does not start up my iOS app if the user closes it.

How to make the iOS to start my app whenever a silent notification is received?

Jemimah answered 8/5, 2018 at 19:55 Comment(7)
Have you enabled background apprefresh for your app on the iPhone itself? see this image. For more see my answer hereDowncome
I didn't notice the part where you said: user closes it. Do you mean the user hit home button twice and swiped the app and killedit? In that scenario you get nothing. That's the expected behavior. Silent notification will open your app if the was suspended or in background state. But not for a user-terminated appDowncome
What you can do is: combine a silent notification and user notification together, ie send content_available as true and then also send alert, sound as well. if the app wasn't killed then since you were using content_available then it will open the app...and if the app was user-terminated then since you sent an alert the user will see the notification and can tap on it and open your appDowncome
Please point me to the official documentation regarding expected behavior. Because Android has different expectation as per my experience.Jemimah
Regarding combining silent and user notifications, my notification should appear based on user's location. So I send a silent notification to all users, and only subset of users actually notified, others just the app discards it.Jemimah
What was the purpose of your last comment? I don't understand. It's not clear what you're trying to sayDowncome
Also see here. You can use PushKit. Though you must have a valid usecase for it. Otherwise Apple may just not approve your app...Downcome
D
8

It's the expected behavior to not launch the app. I mean why should it? The user for some reason has decided to kill the app. They don't want battery or bandwidth getting used for it anymore!

From documentation.

Use this method to process incoming remote notifications for your app. Unlike the application(_:didReceiveRemoteNotification:) method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again


For non-silent notifications. They would get delivered to the device. But not to the app.

If you force-quite your Whatsapp on your iPhone and your mother sends you a message, then your iPhone would show it among its notifications. However it won't trigger any of your AppDelegate methods. AppDelegate methods are only triggered if the app is not user terminated.

Downcome answered 21/5, 2018 at 12:33 Comment(3)
As a small addition: One might wonder "well, doesn't 'the system launches your app' and 'not automatically launch your app if the user has force-quit it' contradict each other?" - No, there is a scenario in which it gets relaunched (technically), but it wasn't inactive due to the user force-quitting it: Device reboot. After a reboot and after the user has unlocked the device at least once, incoming notifications should launch the app (for the user this looks like it was never terminated at all, in spite of rebooting). This is admittedly very hard to test properly, but the designed behavior.Bartender
@Bartender it also get's launched if app was in suspended state ie user clicked home and didn't have any background activity and a few minutes passed. This is also a very common caseDowncome
Yup, that's of course also the case (and good point: people often don't understand the difference between suspended and background). I just wanted to point out a common misconception people have with regard to an app not running, or being "terminated". Both terms are ambiguous, because iOS distinguishes between "not running because killed by the user" and "not running due to reboot or some other system reason". Actually VOIP apps even get launched after the user killed them IIRC, so there's that, too.Bartender

© 2022 - 2024 — McMap. All rights reserved.