LEONetworkKit 是 LEOKit 的一部分。祝您使用愉快!
In me the tiger sniffs the rose.
心有猛虎,细嗅蔷薇。
欢迎来到我的博客: http://LeoDev.me
在 AppDelegate.m
中
#import "LEONetworkKit.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[LEONetworkStatus startInternetNotifier];
return YES;
}
在任意地方获取网络状态
NetworkStatus status = [LEONetworkStatus status];
NSLog(@"Network Status: %ld", status);
或者,您想观察网络状态变化通知
// Notifications
// Network status changed
extern NSString *const kLEONetworkStatusChangedNotification;
// Network toggle to not reachable
extern NSString *const kLEONetworkNotReachableNotification;
// Network toggle to WiFi
extern NSString *const kLEONetworkReachableViaWiFiNotification;
// Network toggle to WWAN (Cellular)
extern NSString *const kLEONetworkReachableViaWWANNotification;
// Add observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNetworkStatusChanged:)
name:kLEONetworkStatusChangedNotification
object:nil];
// Handle net work status changed
- (void)handleNetworkStatusChanged:(NSNotification *)noti {
Reachability *reach = noti.object;
NSParameterAssert([reach isKindOfClass:[Reachability class]]);
NetworkStatus status = reach.currentReachabilityStatus;
NSLog(@"From Notification: %ld", status);
}
startInternetNotifier
时更新网络状态。添加网络状态变化通知
// Network status changed
extern NSString *const kLEONetworkStatusChangedNotification;
如果您有任何问题,请 提交问题!谢谢!
博客: http://LeoDev.me