真機與模擬器判斷+設備類型判斷
#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
NSLog(@" on simulator");
#else
NSLog(@"not on simulator");
#endif
注意:TARGET_OS_IPHONE在真機和模擬器上都是1
設備類型判斷方法有兩種:
1. UI_USER_INTERFACE_IDIOM() 進行區分(ios 3.2以上),但是無法區分iphone和ipod
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//設備爲ipad
} else {
//設備爲iphone 或 ipod
}
2. 使用 UIDevice.model 進行區分 (ios 2.0 >=)
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"]) {
//iPhone
}else if([deviceType isEqualToString:@"iPod touch"]) {
//iPod Touch
}else {
//iPad
}
五、獲取設備相關信息
//軟件信息
NSLog(@"sysname=%@",[[UIDevice currentDevice] systemName]);// 系統名
NSLog(@"systemVersion=%@",[[UIDevice currentDevice] systemVersion]); //版本號
NSLog(@"model=%@",[[UIDevice currentDevice] model]); //類型(ipad、ipod、iphone)而[[UIDevice currentDevice] userInterfaceIdiom]只能判斷iphone和ipad
NSLog(@"olduuid=%@",[[UIDevice currentDevice] uniqueIdentifier]); //唯一識別碼 ios5.0開始deprecated
NSLog(@"name=%@",[[UIDevice currentDevice] name]); //設備名稱
NSLog(@"localizedModel=%@",[[UIDevice currentDevice] localizedModel]); // 本地模式
NSLog(@"ios6UUID=%@",[[[UIDevice currentDevice] identifierForVendor] UUIDString]);//ios6.0開始available
----------注:以下內容未測試,摘自http://www.cnblogs.com/mrhgw/archive/2012/06/27/2565798.html---------------
// 硬件信息
[UIDevice platform];//平臺
[UIDevice cpuFrequency]];//cpu信息
UIDevice busFrequency]];//總線
[UIDevice totalMemory]];//總內存
UIDevice userMemory]];//已經使用的內存
-----------------------------------------------------------------------------------------------------------------------------
//App信息
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
CFShow(infoDictionary);//所有plist內容
// app名稱
NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
// app版本
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// app build版本
NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
判斷是否有照相機
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
NSLog(@"有");
else
NSLog(@"沒有");
六、針對不同分辨率的設備,程序員只需要做三件事:
1.提供app高清圖標;
2.UI圖片素材@2x.png;
3.從網絡下載適配的圖片(判斷條件[[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2)
-所有的iPhone、iPod Touch設備的 Point分辨率都是 320×480,也就是邏輯分辨率都一致,保證了App不需要修改也能正常的在高像素分辨率上運行,只是原來App中的圖片會被拉昇後顯示,影響美觀,沒有發揮retina的優勢。
-程序內所有的GCRectMake都是邏輯分辨率,不影響位置和大小!做遊戲開發最有用,普通app影響不大
-問題:如何進行相對佈局???(6.0之前有autoResizeMask,autoresizing 6.0可使用與android相對佈局類似的autoLayout)