Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How to handle push notification when app was force-quit by user? [iOS]

$
0
0

First of all, just to clarify...

I have done quite some searchings and readings on the existing sources (medium, stackoverflow, apple developer forum, etc.) before asking this "duplicate question" for confirming and concluding my knowledge is correct.

  1. Will iOS launch my app into the background if it was force-quit by the user?
  2. How to get the push notification payload when force-quit / swipe up to kill the iOS app without tapping on the banner/alert?
  3. https://medium.com/fenrir-inc/handling-ios-push-notifications-the-not-so-apparent-side-420891ddf10b
  4. Handling Push Notifications when App is Terminated
  5. https://developer.apple.com/forums/thread/62005#:~:text=In%20most%20cases%2C%20the%20system,force%20quit%20by%20the%20user.

Before we begin, just to put the terms in very precise manner. Here's what I'm referring when I mention

  1. Foreground - App is Active and running, user is basically interacting with the application
  2. Background - User tapped on home button after interacting. App remains in background, user can double tap on home button and find the app from App Switcher.
  3. Quit - App is actually in background, but it was terminated by the System itself.
  4. Kill - App is no longer in background, user double tap on home button and SWIPE the app away from App Switcher.

Use case i'm trying to tackle

App receive push notification in BACKGROUND, QUIT & KILL states then perform certain background actions (updating Application Badge + storing the Notification in device)

  1. For background - Yes I've managed to achieve this by having content-available = 1 sent together in APNS payload. Notification banner appear, background action executed!
  2. For QUIT - Yes I've managed to achieve this by having content-available = 1 sent together in APNS payload. Notification banner appear, background action executed!
  3. For KILL - Notification banner appear, BUT background action is not trigger.

My questions

  1. Whenever app is kill, it's not possible to awake the app to perform any background action when notification is receive?
  2. How does it works for messaging app like Whatsapp?
  3. How should I handle my cases when app is force quit?
  • ONLY if user tapped notification banner, my app gets to run those background actions (Increase badge count + storing the data).

  • Otherwise, if user choose to tap on App Icon to open my app. The pushed notification won't exist in my app at all, including badge count is not increase.

Below are what I've tested with Whatsapp

Background State

  1. Open Whatsapp, tap Home button (keep app in background)
  2. Send a text message in device, banner notification appear
  3. Open app by tapping app icon, message is there in app.

FORCE QUIT State

  1. Open Whatsapp, double tap Home button, swipe app away
  2. Send a text message in device, banner notification appear.
  3. Open app by tapping app icon, message is there in app.

FORCE QUIT State + WiFi & Cellular data turned OFF

  1. Open Whatsapp, double tap Home button, swipe app away
  2. Send a text message in device, banner notification appear
  3. Turn off WiFi & Cellular data is off. (Confirm and tried to access website via Safari)
  4. Open app by tapping app icon, message is there in app.

The tests with Whatsapp, basically concludes that it's possible to have your app awake to perform background actions (Especially with the case of FORCE QUIT State + WiFi & Cellular data turned OFF)

The only "explanation" I'm able to explain myself is, they are using PushKit notifications Framework instead of User Notification Framework.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>