2017-07-26 119 views
1

在我的應用程序中,我試圖使用NetworkReachability獲取網絡狀態。我嘗試了它,當我在無線或3G連接,它完美的作品。iPhone網絡可達性 - 網絡共享被識別爲3G而不是WIFI

的問題是,當我連接到個人熱點/圈養(與iPhone進行測試,以iPhone,Android的iPhone和路由器與SIM),我總是得到3G連接,而不是與ios10 wifi.Tested。沒有使用私有框架來控制我是否處於連接或熱點連接之下嗎?

+0

通過你提到NetworkReachability,沒有人真正知道它到底是。 –

回答

0

你必須檢查可到達互聯網,使用下面的鏈接繼續從蘋果公司下載可達性演示項目:

https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html

,兩者的.h和.m文件添加到項目中。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil]; 

reachability = [Reachability reachabilityForInternetConnection]; 
[reachability startNotifier]; 

- (void) handleNetworkChange:(NSNotification *)notice 
{ 

    NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; 

    if(remoteHostStatus == NotReachable) {NSLog(@"no");} 
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); } 
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); } 
} 
0

GitHubAFNetworking庫提供檢查網絡的可達性狀態。使用Network Reachability Manager目標文件來檢測互聯網可達性狀態。

共享網絡可達性

[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { 
    NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status)); 
}]; 

[[AFNetworkReachabilityManager sharedManager] startMonitoring];