一、判断设备
02 |
return [UIDevice currentDevice].name;
|
05 |
return [UIDevice currentDevice].model;
|
08 |
return [UIDevice currentDevice].systemVersion;
|
11 |
return [UIDevice currentDevice].systemName;
|
02 |
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) |
05 |
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
08 |
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) |
11 |
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f |
二、判断网络连接状态
1、导入SystemConfiguration.framework,并#import<SystemConfiguration/SCNetworkReachability.h>
2、判断设备是否联网
01 |
+ ( BOOL )connectedToNetwork{
|
05 |
struct sockaddr_storage zeroAddress;
|
07 |
bzero(&zeroAddress, sizeof (zeroAddress));
|
08 |
zeroAddress.ss_len = sizeof (zeroAddress);
|
09 |
zeroAddress.ss_family = AF_INET;
|
12 |
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, ( struct sockaddr *)&zeroAddress);
|
13 |
SCNetworkReachabilityFlags flags;
|
16 |
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
|
17 |
CFRelease(defaultRouteReachability);
|
20 |
if (!didRetrieveFlags)
|
26 |
BOOL isReachable = flags & kSCNetworkFlagsReachable;
|
27 |
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
|
28 |
return (isReachable&&!needsConnection) ? YES : NO;
|
三、设备不显示的解决办法
PS:如果设备已经插上,但是XCode不显示当前设备,仍为iOS Device的状态,如下图所示
解决步骤
1.点击XCode右上角的Organizer->Devices,看自己的设备是否为绿灯状态,如果为黄灯或是没有灯,说明设备未连接好,请重新再插一次
2.如果设备已经连接好,但是还是不显示,则说明是系统版本不匹配,如果设备是ios5的系统,则XCode的iOS Deployment Target 必须是5.0或以上,XCode才可分辨此设备
选中TARGETS->Summary-Deployment Target 修改iOS版本号(假设设为6.1)
如果还是不识别,在PROJECT->Info->iOS Deployment Target下将版本号也修改为6.1