網絡判斷需要包含Reachability.h庫,判斷函數如下:
+ (NSString *)checkNetWork
{
Reachability *reachAble = [Reachability reachabilityWithHostName:@"www.baidu.com"];
switch ([reachAble currentReachabilityStatus]) {
case NotReachable:
return @"NONetWork";
break;
case ReachableViaWWAN:
return @"3G";
break;
case ReachableViaWiFi:
return @"WiFi";
break;
}
return @"NONetWork";
} www.2cto.com
ios設備判斷,函數如下:
+ (bool)checkDevice:(NSString *)name
{
NSString* deviceType = [UIDevice currentDevice].model;
NSLog(@"deviceType = %@", deviceType);
NSRange range = [deviceType rangeOfString:name];
return range.location != NSNotFound;
}
這裡的name可以為iPhone、iPod、iPad和iPhone Simulator中一個,通過返回BOOL值來判斷是那種設備。