그래서 여기에 Reachability 구현에 대한 많은 게시물이 있지만 그 중 특정 질문에 대한 답을 찾을 수 없습니다.도달 가능성 hostStatus가 false를 반환 함
다음 코드를 구현 중이지만 hostStatus가 항상 NotReachable로 되돌아옵니다.
내 .H 파일 :
#import <UIKit/UIKit.h>
#import "Reachability.h"
@class Reachability;
@interface ViewController : UIViewController<UINavigationControllerDelegate>{
Reachability* hostReachable;
Reachability* internetReachable;
}
@property (nonatomic, assign) BOOL wifiReachable;
@property (nonatomic, assign) BOOL networkReachable;
@property (nonatomic, assign) BOOL internetUsable;
내하는 .m 파일 :
#import "ViewController.h"
#import "Reachability.h"
#import "Reachability.m"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [Reachability reachabilityForInternetConnection];
hostReachable = [Reachability reachabilityWithHostName:@"www.google.com"];
[internetReachable startNotifier];
[hostReachable startNotifier];
// now patiently wait for the notification
[self checkNetworkStatus:kReachabilityChangedNotification];
if(self.internetUsable==TRUE){
//DO STUFF
}
else{
[self internetAlert];
//DO OTHER STUFF
}
}
-(void) checkNetworkStatus:(NSNotification *)notice{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
NSLog(@"%u", hostStatus);
if(internetStatus==NotReachable){
NSLog(@"The internet is down.");
self.internetUsable=FALSE;
}
else{
if(internetStatus==ReachableViaWWAN){
NSLog(@"The internet is working via WWAN.");
self.networkReachable=TRUE;
self.internetUsable=TRUE;
}
else if (internetStatus==ReachableViaWiFi) {
NSLog(@"The internet is working via WIFI.");
self.wifiReachable=TRUE;
self.internetUsable=TRUE;
}
else{
self.networkReachable=FALSE;
self.wifiReachable=FALSE;
self.internetUsable=FALSE;
NSLog(@"The internet is NOT useable.");
}
}
if(self.internetUsable==TRUE)
{
if(hostStatus==NotReachable)
{
self.internetUsable=FALSE;
NSLog(@"Could not connect to the host");
}
}
}
내 생각 엔이 hostStatus 연결이 제대로 확인되기 전에는 CheckNetworkStatus 방법에 진입하고 있다는 점이다.
도움이 될만한 정보가 있습니까?