如何以编程方式检测iPhone XS或iPhone X?

编程入门 行业动态 更新时间:2024-10-24 12:27:25
本文介绍了如何以编程方式检测iPhone XS或iPhone X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的一个应用程序连接到一个Web应用程序服务,该服务向用户提供特定于设备的新闻。为了使其适应最新的iPhone版本,我需要以编程方式区分iPhone XS和iPhone X.如何做到这一点?

One of my apps connects to a web app service that delivers device specific news to to the user. To adapt this to the latest iPhone versions I need to programmatically distinguish between the iPhone XS and iPhone X. How can this be done?

[[ UIScreen mainScreen] bounds] .size 总是一个很好的起点,可以分辨出不同的设备。但是,iPhone XS和iPhone X具有相同的屏幕尺寸:1125 x 2436.因此,使用 [[UIScreen mainScreen] bounds] .size 在这种情况下不起作用。

[[UIScreen mainScreen] bounds].size was always a good starting point to tell the different devices apart. However, iPhone XS and iPhone X have the same screen dimensions: 1125 x 2436. Thus using [[UIScreen mainScreen] bounds].size does not work in this case.

有没有其他方法可以检测最新的iPhone版本?

Is there any other method to detect the latest iPhone versions?

编辑: 这是不重复的问题如何检测iPhone X,因为那里讨论的所有答案/解决方案都使用屏幕尺寸来指定设备类型。如上所述,iPhone X和iPhone XS具有完全相同的尺寸,因此解决方案无法区分这两者......

This is NOT a duplicate of the question "How to detected iPhone X" since all answers/solutions discussed there use the screen dimensions to specify the device type. As described above iPhone X and iPhone XS have the exact same dimensions and thus the solutions cannot tell these two apart...

推荐答案

我使用 DeviceUtil 来确定iOS设备的型号。

I use DeviceUtil to determine an iOS device's model.

根据这个 DeviceUtil GitHub帖子,返回的UIDevice hardwareString值是:

According to this DeviceUtil GitHub post, the returned UIDevice hardwareString values are:

iPhone11,2 = iPhone XS iPhone11,4 = iPhone XS Max iPhone11,8 = iPhone XR

奇怪的是,Xcode 10 GM模拟器的[UIScreen mainScreen] .bounds.size返回375 x 812适用于iPhone X,XS,XS Max和R设备。我原本预计XS Max和XR会有414 x 896.

Curiously, the Xcode 10 GM Simulator's [UIScreen mainScreen].bounds.size returns 375 x 812 for iPhone X, XS, XS Max, and R devices. I had expected 414 x 896 for the XS Max and XR.

更多推荐

如何以编程方式检测iPhone XS或iPhone X?

本文发布于:2023-11-27 20:15:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   iPhone   XS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!