SCNetworkReachabilitySetCallback callbacks with inactive app (in background)

I'm using SCNetworkReachabilitySetCallback to detect network reachability changes. Also I'm using push notifications in my app. I'm stacked with this scenario:


  1. turn off network and go to background
  2. push notification subscription is aborted with 1009 error code (no internet)
  3. wait for a minute
  4. turn on network


The problem is that app goes to background and reachability callbacks are not coming to my iPhone anymore. So I can't subscribe to push notifications until I will not go to foreground in my app.


I checked with Telegram - push notifications are coming to their app with this scenario. Does anyone know how to solve this problem?

Thanks a lot for your answers.

Replies

I’d like to clarify your scenario. Specifically:

  • When is your app launched?

  • In step 2, is this a subscription that you set up before step 1? Or a new request that you started between step 1 and 2.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

My app was launched right before step 1.

No, this is a subscription after turning off the internet (in our app, we subscribe to push channel when we go to background and unsubscribe in foreground).

we subscribe to push channel when we go to background and unsubscribe in foreground

Why are you doing that? It seems like you’re doing extra work to cause this problem )-:

As to your specific question, there is no API that will resume your app in the background when network connectivity changes. Specifically, with regards

SCNetworkReachability
(and its logical replacement,
NWPathMonitor
) it will definitely not resume you in the background on reachability changes. Rather, your app will stay suspended in the background until something else resumes it, or the user brings it to the front, at which point reachability will update you on any state changes.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

This is a historical behavior of the app which I support because of some reasons. Looks like we need to redesign it.

Thanks a lot for your support, eskimo!