在項目開發中有時我們需要獲得設備或app的一些信息並傳遞給後臺,如新註冊用戶獎勵現金20元,爲了防止惡意註冊,就需要拿到設備信息,只要該設備註冊過,再在該設備上註冊的用戶則無獎勵
UIDevice *device = [[UIDevice alloc] init];
NSLog(@"設備所有者名稱 %@ ",device.name);//設備所有者名稱
NSLog(@"設備類別 %@",device.model);//設備leibie
NSLog(@"本地化版本 %@",device.localizedModel);//本地化版本
NSLog(@"當前系統版本 %@",device.systemVersion);//當期版本
NSLog(@"當前系統 %@",device.systemName);//當前系統
NSLog(@"系統唯一標示符 %@",[[[UIDevice currentDevice ] identifierForVendor] UUIDString]);//唯一標示
NSLog(@"電量 %f",[[UIDevice currentDevice] batteryLevel]);//輸出-1爲模擬器 輸出0-1爲真機
NSArray *languageArray = [NSLocale preferredLanguages];
NSString *language = [languageArray objectAtIndex:0];
NSLog(@"語言:%@", language);//語言
NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale localeIdentifier];
NSLog(@"國家:%@", country); //國別
//獲得運營商信息
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
// 獲取運行商的名稱
CTCarrier *carrier = [info subscriberCellularProvider];
NSString *mCarrier = [NSString stringWithFormat:@"%@",[carrier carrierName]];
NSLog(@"%@", mCarrier);
//app應用相關信息的獲取
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];
NSLog(@"應用所有信息 %@",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);
NSString *strAppBundleIdentifier = [dicInfo objectForKey:@"CFBundleIdentifier"];
NSLog(@"App應用唯一標示符:%@", strAppBundleIdentifier);