0

Is it safe to use 'com.apple.system.config.network_change' notification to detect network reachability changes? Or is it considered to be a private API? For now my code looks like this:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                nil,
                                callback,
                                "com.apple.system.config.network_change" as CFString,
                                nil,
                                .deliverImmediately);

And then in callback I respond to the notification.

The problem is Reachability in iOS not always detects Wi-Fi switching. For instance, if we are switching from one Wi-Fi AP to the other that system already knows (because we have used it in the past) then it happens so fast that there's no 'Disconnected' event and I cannot track the actual switching moment. Solution above works but I am sure whether my app won't be rejected for publishing in the App Store.

Thanks!

Yura
  • 1
  • 1

2 Answers2

0

I can't exactly answer your question, but the way I handle Reachability changes is using this "lib", which is pretty accurate when listening to every single change. I think you could give it a try if it fits your needs of detecting this specific moment of switching between two Wi-Fis.

If you don't want to import it - it's a really small file -, you can just see how it works - basically using SCNetworkReachability.

Guilherme Matuella
  • 2,193
  • 1
  • 17
  • 32
  • I have already tried it but still under the hood it uses SCNetworkReachability and all other libraries do it too. And so in the situation that I described id doesn't recognize Wi-Fi AP change :( – Yura Oct 03 '18 at 13:20
  • Are you trying to check it in a simulator? See [this question update](https://stackoverflow.com/q/45959705/8558606) - he had a problem specifically when testing with a simulator. – Guilherme Matuella Oct 03 '18 at 13:37
  • 1
    No, I use different devices and behavior is the same everywhere. – Yura Oct 03 '18 at 15:18
0

That is considered to be a public API for now. For more details please see this thread:

https://forums.developer.apple.com/message/334035#334035

Yura
  • 1
  • 1