Comments (7)
I would move this check out of applicationDidFinishLaunchingWithOptions because it can take more than 10 seconds. You should schedule things to start happening in applicationDidFinishLaunchingWithOptions and get out of that method as fast as you can.
For instance, you could dispatch_async [reachHost startNotifier] and return from applicationDidFinishLaunchingWithOptions.
from reachability.
Thanks pburleson
I did try dispatch_async [reachHost startNotifier] but this didn't seem to make any difference to the reachable = [reachHost isReachable]; call which I can see it hanging on for a while before returning,
Should I be doing this somewhere else?
from reachability.
yes, unfortunately under poor network connectivity Reachability can hang in certain situations.
if you try something like:
reachable = NO;
reachHost = [Reachability reachabilityWithHostname:@"www.google.com"];
reachHost.reachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
reachable = YES;
});
};
reachHost.unreachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
reachable = NO;
});
};
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
reachable = [reachHost isReachable];
[reachHost startNotifier];
}
Then the initial detection will happen on a background thread, then the notifier will start up. Notice I put both the initial detection and the startNotifier in the async call.
from reachability.
I'm trying to remember if Reachability has to be run on the main thread, but if it doesn't you should use the global queue instead of the main queue, as that continues to hang the main thread and will get you watchdog killed.
from reachability.
In addition, I'm curious why you need to run the initial isReachable?
Generally its better to try any network operations you were going to do, and catch them if they fail, queue them to be retried later, then when Reachability notifies you you have connectivity replay the queued operations.
from reachability.
isReachable shouldn't be called on app startup (on the main thread). Use the notification or blocks instead to update the reachability status. isReachable will block in low network situations which can result in the watchdog killing your app if it hangs for more than 20s. This will happen with Apple's reachability code too. I think it may talk about this in the readme or header in Apple's example.
from reachability.
I moved the isReachable check to a block and this works a lot better,
Tony, I agree it would be better not to call the initial isReachable but I'm making a data call to check for updates for my app as part of the launch, so i need to check for a connection.
Thanks for your replies all, will close if no further comments..
from reachability.
Related Issues (20)
- Always detecting ReachableViaWiFi 'TRUE' in iOS 11 HOT 3
- connection vpn and always callback noreachable
- NSNotification.Name.reachabilityChanged does not work HOT 1
- warning of leak in Xcode
- SIGABRT in TMReachabilityCallback HOT 1
- Why NetworkStatus rawValue dose not match to the Apple's Reachability ?
- iOS12 bug, API cannot callback normal! HOT 1
- Airplane mode with shadowsocks return reachable
- Attempted to dereference garbage pointer HOT 1
- Crash on iOS 12 (Crashed: com.tonymillion.reachability)
- Not work on iOS 13.2.3, iPad Mini 4 HOT 1
- add support to swift package manager
- Symbol not found HOT 2
- Semantic issue cast from pointer to smaller type 'unsigned int' loses information when compile source as Objective-C++
- SCNetworkReachabilityCreateWithAddress Thread 1: EXC_BAD_ACCESS (code=2, address=0x16b04bff0)
- iOS14 always get reachable on 4G with wrong hostname HOT 1
- Uio
- cast to smaller integer type 'unsigned int' from 'Reachability *' [-Wpointer-to-int-cast] NSStringFromClass([self class]), (unsigned int) self, [self currentReachabilityFlags]]; HOT 3
- Privacy manifest required by Apple HOT 12
- How to import privacy list๏ผ look here HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reachability.