你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS獲取設備型號和App版本號等信息

iOS獲取設備型號和App版本號等信息

編輯:IOS開發綜合

// 獲取以後App的根本信息字典NSDictionary*infoDictionary=[[NSBundlemainBundle]infoDictionary]; //app稱號NSString*app_Name=[infoDictionaryobjectForKey:@"CFBundleDisplayName"];//app版本NSString*app_Version=[infoDictionaryobjectForKey:@"CFBundleShortVersionString"];//appbuild版本NSString*app_build=[infoDictionaryobjectForKey:@"CFBundleVersion"]; //手機序列號NSString*identifierNumber=[[UIDevicecurrentDevice]uniqueIdentifier]; //手機別名:用戶定義的稱號NSString*userPhoneName=[[UIDevicecurrentDevice]name]; //設備稱號NSString*deviceName=[[UIDevicecurrentDevice]systemName]; //手機零碎版本NSString*phoneVersion=[[UIDevicecurrentDevice]systemVersion]; //手機型號NSString*phoneModel=[[UIDevicecurrentDevice]model]; //中央型號(國際化區域稱號)NSString*localPhoneModel=[[UIDevicecurrentDevice]localizedModel];

IOS開發進程中,有時分為了更好的用戶體驗或許為了bug跟蹤,能夠會需求獲取用戶的使用信息、零碎信息、設備信息。這些信息的獲取可以依據不同的設備或許App、零碎版原本提供不同的功用或更好的用戶體驗,或許讓開發者能更好的剖析用戶的問題緣由。

你說不要啰嗦了:Talk is cheap, show me the code!

好的,code來了:

獲取設備稱號
OC代碼
NSString *deviceName = [[UIDevice currentDevice] name];
Swift代碼
let deviceName = UIDevice.currentDevice().name獲取零碎版本號
OC代碼
NSString *sysVersion = [[UIDevice currentDevice] systemVersion];
Swift代碼
let sysVersion = UIDevice.currentDevice().systemVersion獲取設備獨一標識符
OC代碼
NSString *deviceUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
Swift代碼
let deviceUUID = UIDevice.currentDevice().identifierForVendor?.UUIDString獲取設備的型號
OC代碼
NSString *deviceModel = [[UIDevice currentDevice] model];
Swift代碼
let deviceModel = UIDevice.currentDevice().model獲取App相關的信息
OC代碼
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
// 獲取App的版本號NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
// 獲取App的build版本NSString *appBuildVersion = [infoDic objectForKey:@"CFBundleVersion"];
// 獲取App的稱號NSString *appName = [infoDic objectForKey:@"CFBundleDisplayName"];
Swift代碼
let infoDic = NSBundle.mainBundle().infoDictionary
// 獲取App的版本號let appVersion = infoDic?["CFBundleShortVersionString"]
// 獲取App的build版本let appBuildVersion = infoDic?["CFBundleVersion"]
// 獲取App的稱號let appName = infoDic?["CFBundleDisplayName"]

有些人能夠會說了:“褲子都脫了,你就給我看這個!看你之前寫的博客還能看點兒干貨,明天第一篇就寫著麼個玩意兒?尤其是獲取設備型號那個,獲取出來一個iPhone,你確定不是在逗我吧?”

看官別急,其實這次最次要的就是來分享獲取設備型號的辦法的,由於我看國際還很少有Swift寫的一些東西,也不知道是不是由於我沒有找到,就想自己寫出來給大家分享,特地做個筆記。

你會說:獲取設備型號比擬費事,又用的是C言語的一些東西,比擬費事,而且還得記住一切設備版本號例如:iPhone8,2,真實是記不住啊。當然不必記住,用的時分拷過去就行了,由於我也記不住

【iOS獲取設備型號和App版本號等信息】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved