1
A
回答
2
我已經使用AFNetworking
,並發現它是最容易使用這個(監聽適配器的變化)
#import <AFNetworking/AFNetworkReachabilityManager.h>
- (instancetype)init
{
self = [super init];
if(self)
{
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:AFNetworkingReachabilityDidChangeNotification
object:nil];
}
return self;
}
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AFNetworkingReachabilityDidChangeNotification
object:nil];
}
,然後實現處理程序:
- (void)reachabilityChanged:(NSNotification *)notification
{
NSNumber *s = notification.userInfo[AFNetworkingReachabilityNotificationStatusItem];
AFNetworkReachabilityStatus status = [s integerValue];
//Check value of status here
}
這裏是頭在那裏你可以看到用於狀態的常量: https://github.com/AFNetworking/AFNetworking/blob/4fb051898c60051d207ca0c24435766fdf140e34/AFNetworking/AFNetworkReachabilityManager.h
我也用過SCReachability
#import <SystemConfiguration/SystemConfiguration.h>
BOOL networkAvailable = NO;
const char *hostName = [NEVER_TRANSLATE(@"google.com") cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkReachabilityFlags flags = 0;
SCNetworkReachabilityRef target = SCNetworkReachabilityCreateWithName(NULL, hostName);
if (SCNetworkReachabilityGetFlags(target, &flags))
{
if (flags == kSCNetworkFlagsReachable)
{
networkAvailable = YES;
}
}
雖然我用這個在特定的時間來檢測,而不是註冊爲一個監聽網絡的可用性,所以不知道這是否會做你想做
相關問題
- 1. 區分VMware網絡適配器與物理網絡適配器 - 或 - 檢測虛擬網絡適配器
- 2. windows網絡適配器
- 3. 列出網絡適配器
- 4. 創建映像會更改網絡適配器名稱
- 5. 更改無線網絡適配器無線模式屬性
- 6. 捕獲網絡適配器上/下和地址更改事件(Windows,C#)
- 7. 如何通過powershell更改禁用的網絡適配器配置
- 8. Windows腳本來檢測,如果網絡適配器需要重置
- 9. HttpURLConnection&使用特定網絡適配器
- 10. 網絡適配器批處理標識
- 11. NIC卡和網絡適配器?
- 12. 在ubuntu上設置網絡適配器
- 13. 更改適配器數據
- 14. 檢測網絡是否改變?
- 15. 使用所需的網絡適配器撥打網絡服務
- 16. 如何更改使用c#的網絡適配器的接口指標?
- 17. 如何使用Node.js檢測網絡更改
- 18. 用於兩級檢測的更改SSD網絡(Single Shot Multibox Detector)
- 19. 使用NSTask更改osx網絡配置
- 20. 在C中更改網絡配置#
- 21. 如何檢查網絡更改iphone
- 22. 檢測網絡服務器類型
- 23. 檢測網絡驅動器掛載wmi
- 24. 網頁瀏覽器控件,檢測網絡連接
- 25. SharedPrefereces更改後更新RecyclerView適配器
- 26. android GPRS檢測網絡?
- 27. 檢測網絡連接
- 28. Facebook網絡釣魚檢測
- 29. 可能檢測硬件?
- 30. 檢測GPS硬件在iphone
什麼這正是我一直在尋找,謝謝您! –