很多時(shí)候,我們需要獲得用戶iPhone版本號,或者App的當(dāng)前版本號。
關(guān)心以下兩個(gè)方面:
一、App項(xiàng)目中,應(yīng)用程序邏輯會根據(jù)iPhone硬件的版本號來進(jìn)行相應(yīng)的處理。版本不同,有些開發(fā)方法、環(huán)境都不同。
二、由于某種需求(如更新什么的),我們需要得到我們App的當(dāng)前版本。
一、獲得客戶端用戶的硬件版本號
//?判斷設(shè)備的iOS?版本號
float?version = [[[UIDevice?currentDevice]?systemVersion]?floatValue];
NSLog(@"%f",version);
二、我們還可以獲得更多相應(yīng)的設(shè)備信息
NSLog(@"%@",[[UIDevice?currentDevice]?name]);?// 用戶為手機(jī)取的名字,如:"My Phone"
NSLog(@"%@",[[UIDevice?currentDevice]?identifierForVendor]);?// 像字符串類型的UUID,如:(iOS 6.0)
NSLog(@"%@",[[UIDevice?currentDevice]?systemName]);?// 操作系統(tǒng)名稱,如:"iPhone OS"
NSLog(@"%@",[[UIDevice?currentDevice]?systemVersion]);?// 操作系統(tǒng)版本號,如:"5.1.1"
NSLog(@"%@",[[UIDevice?currentDevice]?model]);?// "My Phone" 的當(dāng)前最新版本
NSLog(@"%@",[[UIDevice?currentDevice]?localizedModel]);?// "My Phone" 的本地化版本
三、獲得App的版本號
//?獲得軟件的版本號,
NSDictionary* infoDict =[[NSBundle?mainBundle]?infoDictionary];//讀取?Info.plist文件的信息。
float?softVerson =[[infoDict objectForKey:@"CFBundleShortVersionString"] floatValue];
這樣,版本號就獲取成功了。