IOS擷取裝置及App相應資訊

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   sp   for   on   art   

 

iOS的SDK中提供了UIDevice,NSBundle,NSLocale,UIScreen等類來擷取裝置、app等相應的資訊。

 

UIDevice用於擷取裝置相應的資訊,如裝置名稱、裝置唯一標識、系統名稱、系統版本號碼、裝置模式、本地裝置模式等。

 

NSBundle用於擷取App相應的資訊,如應用程式名稱、應用版本、應用Build版本等。

 

NSLocale用於擷取使用者的本地化資訊設定,例如貨幣類型,國家,語言,數字,日期格式的格式化,提供正確的地理位置顯示等。

 

UIScreen用於擷取裝置的螢幕尺寸和解析度。

 

 

相應代碼如下:

 

//裝置相關資訊的擷取
NSString *strName = [[UIDevice currentDevice] name];
NSLog(@"裝置名稱:%@", strName);//e.g. "My iPhone"

NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"裝置唯一標識:%@", strId);//UUID,5.0後不可用

NSString *strSysName = [[UIDevice currentDevice] systemName];
NSLog(@"系統名稱:%@", strSysName);// e.g. @"iOS"

NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@"系統版本號碼:%@", strSysVersion);// e.g. @"4.0"

NSString *strModel = [[UIDevice currentDevice] model];
NSLog(@"裝置模式:%@", strModel);// e.g. @"iPhone", @"iPod touch"

NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
NSLog(@"本地裝置模式:%@", strLocModel);// localized version of model

 

//app應用相關資訊的擷取
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];
// CFShow(dicInfo);

NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];
NSLog(@"App應用程式名稱:%@", strAppName);

NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];
NSLog(@"App應用版本:%@", strAppVersion);

NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];
NSLog(@"App應用Build版本:%@", strAppBuild);

 

 

//Getting the User’s Language
NSArray *languageArray = [NSLocale preferredLanguages];
NSString *language = [languageArray objectAtIndex:0];
NSLog(@"語言:%@", language);//en

NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale localeIdentifier];
NSLog(@"國家:%@", country); //en_US

 

//螢幕尺寸

CGRect rect = [[UIScreen mainScreen] bounds];

CGSize size = rect.size;

CGFloat width = size.width;

CGFloat height = size.height;

NSLog(@"寬、高:%f,%f",width,height);

 

//解析度

CGFloat scale_screen = [UIScreen mainScreen].scale;

NSLog(@"screen w:%f",width*scale_screen);

NSLog(@"screen h:%f",height*scale_screen);

 

參考:

http://blog.csdn.net/xyz_lmn/article/details/8968196

http://blog.csdn.net/tangaowen/article/details/7597535

 

IOS擷取裝置及App相應資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.