- Xcode 7 or higher
- iOS 8.0 or higher
- ARC
CDNetworkReachability is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CDNetworkReachability'
- 开启监测
CDNetworkReachability *reachability = [CDNetworkReachability manager];
//[CDNetworkReachability reachabilityWithHostName:@"www.baidu.com"];
[reachability startNotifier];
- 检测网络权限
[[CDNetworkReachability manager] checkNetworkPermissionsEvent:^(CDNetworkAuthorizationStatus status) {
if (status == CDNetworkAuthorizationRestricted) {
//没有网络授权
}
}];
- 获取当前网络状态
[reachability currentReachabilityStatus];
- 网络状态发生变化的回调
[[CDNetworkReachability manager] setReachabilityStatusChangeBlock:^(CDNetworkStatus status) {
}];
cqzhong, 2863802082@qq.com
CDNetworkReachability is available under the MIT license. See the LICENSE file for more info.