如何以编程方式检测设备运行在哪个IOS版本上?

如何以编程方式检测设备运行在哪个IOS版本上?

我想检查用户是否在iOS上运行的应用程序少于5.0,并在应用程序中显示一个标签。

如何以编程方式检测用户设备上运行的IOS?

谢谢!


撒科打诨
浏览 607回答 3
3回答

一只萌萌小番薯

更新在iOS 8中,我们可以使用新的isOperatingSystemAtLeastVersion方法上NSProcessInfo&nbsp;&nbsp;&nbsp;NSOperatingSystemVersion&nbsp;ios8_0_1&nbsp;=&nbsp;(NSOperatingSystemVersion){8,&nbsp;0,&nbsp;1}; &nbsp;&nbsp;&nbsp;if&nbsp;([[NSProcessInfo&nbsp;processInfo]&nbsp;isOperatingSystemAtLeastVersion:ios8_0_1])&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;iOS&nbsp;8.0.1&nbsp;and&nbsp;above&nbsp;logic &nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;iOS&nbsp;8.0.0&nbsp;and&nbsp;below&nbsp;logic &nbsp;&nbsp;&nbsp;}请注意,这将在IOS 7上崩溃,因为API在IOS 8之前并不存在。if&nbsp;([NSProcessInfo&nbsp;instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)])&nbsp;{ &nbsp;&nbsp;//&nbsp;conditionally&nbsp;check&nbsp;for&nbsp;any&nbsp;version&nbsp;>=&nbsp;iOS&nbsp;8&nbsp;using&nbsp;'isOperatingSystemAtLeastVersion'}&nbsp;else&nbsp;{ &nbsp;&nbsp;//&nbsp;we're&nbsp;on&nbsp;iOS&nbsp;7&nbsp;or&nbsp;below}原文答案IOS<8为了完整起见,以下是苹果自己在iOS 7 UI过渡指南,这涉及到检查“基础框架”版本。if&nbsp;(floor(NSFoundationVersionNumber)&nbsp;<=&nbsp;NSFoundationVersionNumber_iOS_6_1)&nbsp;{ &nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;resources&nbsp;for&nbsp;iOS&nbsp;6.1&nbsp;or&nbsp;earlier}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;resources&nbsp;for&nbsp;iOS&nbsp;7&nbsp;or&nbsp;later}

尚方宝剑之说

我知道我回答这个问题太迟了。我不确定我的方法是否仍然适用于低iOS版本(<5.0):NSString *platform = [UIDevice currentDevice].model;NSLog(@"[UIDevice currentDevice].model: %@",platform);NSLog(@"[UIDevice currentDevice].description: %@",[UIDevice currentDevice].description);NSLog(@"[UIDevice currentDevice].localizedModel: %@",[UIDevice currentDevice].localizedModel);NSLog(@"[UIDevice currentDevice].name: %@",[UIDevice currentDevice].name);NSLog(@"[UIDevice currentDevice].systemVersion: %@",[UIDevice currentDevice].systemVersion);NSLog(@"[UIDevice currentDevice].systemName: %@",[UIDevice currentDevice].systemName);您可以得到以下结果:[UIDevice currentDevice].model: iPhone[UIDevice currentDevice].description: <UIDevice: 0x1cd75c70>[UIDevice currentDevice].localizedModel: iPhone[UIDevice currentDevice].name: Someones-iPhone002[UIDevice currentDevice].systemVersion: 6.1.3[UIDevice currentDevice].systemName: iPhone OS
打开App,查看更多内容
随时随地看视频慕课网APP