Last active
August 29, 2015 14:02
-
-
Save JeOam/049076e7960630b6303b to your computer and use it in GitHub Desktop.
提示网络状况
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <AFNetworkReachabilityManager.h> | |
#import <MBProgressHUD.h> | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
// Override point for customization after application launch. | |
// 当前网络连接情况 | |
AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager]; | |
[afNetworkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { | |
switch (status) { | |
case AFNetworkReachabilityStatusNotReachable:{ | |
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.window animated:YES]; | |
hud.labelText = @"网络连接不可用,请稍候重试"; | |
[hud show:YES]; | |
[hud hide:YES afterDelay:3]; | |
NSLog(@"Block says Network unreachable"); | |
break; | |
} | |
case AFNetworkReachabilityStatusReachableViaWiFi:{ | |
NSLog(@"AFNetworkReachabilityStatusReachableViaWiFi"); | |
break; | |
} | |
case AFNetworkReachabilityStatusReachableViaWWAN:{ | |
break; | |
NSLog(@"AFNetworkReachabilityStatusReachableViaWWAN"); | |
} | |
default: | |
break; | |
} | |
}]; | |
[afNetworkReachabilityManager startMonitoring]; | |
self.window.backgroundColor = [UIColor whiteColor]; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment