Our Objective-C app requires detection of network reachability changes. CocoaPods offers currently way too many alternatives, so we don't know how to select one.
All reachability pods uses either SCNetworkReachabilityScheduleWithRunLoop
or SCNetworkReachabilitySetDispatchQueue
: are there behaviour differences to expect from one or the other? (apart from trivial support of iOS 2 and iOS 3 for the first one)
Last comment from Oleg on Mike Ash blog reads:
What bothers me is the potential race condition that can occur when I call SCNetworkReachabilityGetFlags in a helper thread, while the SCNetworkReachabilityScheduleWithRunLoop has already been set in the main run loop.
There are going to be two different threads both checking for network reachability at the same time and returning their result to the main thread. If network status changes somewhere in between, the events may appear in the run loop queue in an incorrect order.
Is there a way to guarantee the correct event order? Ideally, to make the SCNetworkReachabilityScheduleWithRunLoop to trigger events upon request (not only upon actual network status change)
As we'd like to figure out which pods are the most reliable, is SCNetworkReachabilitySetDispatchQueue
addressing a solution to Oleg's race condition issue? Or is there a pattern to solve race condition issues that we should look for when choosing a pod?
To list a few examples, here is what we noticed...
They use SCNetworkReachabilityScheduleWithRunLoop
:
- https://github.com/AFNetworking/AFNetworking Jan 2016
- https://github.com/skywite/SWReachability Jun 2015
- https://github.com/kstenerud/KSReachability May 2015
- https://github.com/nicklockwood/FXReachability Mar 2015
- https://github.com/jaredsinclair/JTSReachability Aug 2014
- https://github.com/Abizern/NPReachability May 2014
- https://github.com/dev5tec/FBNetworkReachability Mar 2014
- https://developer.apple.com/library/content/samplecode/Reachability/ Dec 2015
They use SCNetworkReachabilitySetDispatchQueue
:
- https://github.com/belkevich/reachability-ios Jan 2016
- https://github.com/dustturtle/RealReachability Jan 2016
- https://github.com/sger/SGReachability Oct 2015
- https://github.com/GlennChiu/GCNetworkReachability Jun 2014
- tonymillion's reachability, but he claims it gets rejected by Apple