在开发中,需要获取当前设备的一些信息,可以通过UIDevice,NSbundle,NSlocale获取.
UIDevice
UIDevice 提供了多种属性,类函数及状态通知,可以检测手机电量,定位,感应,机型,当前系统版本等等.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //设备相关信息的获取 NSString *strName = [[UIDevice currentDevice] name]; NSLog (@ "设备名称:%@" , strName); //e.g. "My iPhone" 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 |
NSBundle
bundle 是一个目录,其中包含了程序会使用到的资源,这些资源包含了图像,声音,编译好的代码,通过这些亦可获取一些应用信息.
1 2 3 4 5 6 7 8 9 10 11 12 | /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); |
NSLocale
NsLocale可以获取用户的本地化信息,如货币,语言,国家,数字,日期格式,地理位置显示等等.
1 //Getting the User’s Language 2 NSArray *languageArray = [NSLocale preferredLanguages]; 3 NSString *language = [languageArray objectAtIndex:0]; 4 NSLog(@"语言:%@", language);//en 5 6 NSLocale *locale = [NSLocale currentLocale]; 7 NSString *country = [locale localeIdentifier]; 8 NSLog(@"国家:%@", country); //en_US
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】