开发者

Disable button when no internet connection

开发者 https://www.devze.com 2023-04-01 19:45 出处:网络
How do I disable a button when there is no connection to a netw开发者_StackOverflowork / internet in iOS?Check out the reachability code from Apple.

How do I disable a button when there is no connection to a netw开发者_StackOverflowork / internet in iOS?


Check out the reachability code from Apple.

http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

and use it like this:

Reachability *reachabilityInstance = [[Reachability reachabilityForInternetConnection] retain];
[reachabilityInstance startNotifier];
NetworkStatus networkStatus = [reachabilityInstance currentReachabilityStatus];
BOOL connected = (networkStatus==ReachableViaWiFi || networkStatus==ReachableViaWWAN);


You can simply hide a button whenever you need to

[button setHidden:YES];
0

精彩评论

暂无评论...
验证码 换一张
取 消