//設備名稱 return [UIDevice currentDevice].name; //設備型號,只可獲得是何設備,沒法獲得是第幾代設備 return [UIDevice currentDevice].model; //系統版本型號,如iPhone OS return [UIDevice currentDevice].systemVersion; //系統版本名稱,如6.1.3 return [UIDevice currentDevice].systemName;
//判斷是否爲iPhone #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) //判斷是否爲iPad #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //判斷是否爲ipod #define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) //判斷是否爲iPhone5 #define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
一、導入SystemConfiguration.framework,並#import<SystemConfiguration/SCNetworkReachability.h>ios
二、判斷設備是否聯網網絡
+ (BOOL)connectedToNetwork{ //建立零地址,0.0.0.0的地址表示查詢本機的網絡鏈接狀態 struct sockaddr_storage zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.ss_len = sizeof(zeroAddress); zeroAddress.ss_family = AF_INET; // Recover reachability flags SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); SCNetworkReachabilityFlags flags; //得到鏈接的標誌 BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); CFRelease(defaultRouteReachability); //若是不能獲取鏈接標誌,則不能鏈接網絡,直接返回 if (!didRetrieveFlags) { return NO; } //根據得到的鏈接標誌進行判斷 BOOL isReachable = flags & kSCNetworkFlagsReachable; BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; return (isReachable&&!needsConnection) ? YES : NO; }
PS:若是設備已經插上,可是XCode不顯示當前設備,仍爲iOS Device的狀態,以下圖所示ui
解決步驟spa
1.點擊XCode右上角的Organizer->Devices,看本身的設備是否爲綠燈狀態,若是爲黃燈或是沒有燈,說明設備未鏈接好,請從新再插一次.net
2.若是設備已經鏈接好,可是仍是不顯示,則說明是系統版本不匹配,若是設備是ios5的系統,則XCode的iOS Deployment Target 必須是5.0或以上,XCode纔可分辨此設備code
選中TARGETS->Summary-Deployment Target 修改iOS版本號(假設設爲6.1)orm
若是仍是不識別,在PROJECT->Info->iOS Deployment Target下將版本號也修改成6.1ip