开发者

Internet reachability with iphone

开发者 https://www.devze.com 2022-12-18 17:35 出处:网络
I need to restart a download automatically when a connection goes down and then comes back up. Actually I\'m using the Reachability class example from Apple but I have a problem when the switch down

I need to restart a download automatically when a connection goes down and then comes back up. Actually I'm using the Reachability class example from Apple but I have a problem when the switch down and up wi-fi application restarts the download, but this does not happen if I have wi-fi but not an internet connection. To do this I check connection and I register method to notification but this notification is never fired.

hostReach = [NaviReachability reachabilityWithHostName:@"www.apple.com"]; internetReach = [NaviReachability reachabilityForInternetConnection]; wifireach = [NaviReachability reachabilityForLocalWiFi]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeDownloadOnNotification:) name:@"kNetworkReachabilityChangedNotification" object:nil];

[hostReach startNotifer]; [internetReach startNotifer]; [wifireach startNoti开发者_JAVA技巧fer]; Blockquote

I noticed that if my application makes a connection (or iphone receives or sends something from internet) the notification arrives, and the method is executed.

Do any of you have any suggestions?


From what I hear the Reachability class is poorly written and one guy has gone as far as to refactor and improve it. He also offers an explanation of how to use his improved version. Maybe it can be of use to your project.

0

精彩评论

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