如何在钛框架中检测iOS的模型

qeeaahzv  于 2023-10-21  发布在  iOS
关注(0)|答案(1)|浏览(86)

例如:iPad Pro第3代以后由于引入底部黑条凹口。在iPad Pro第一代和第二代中不存在。四代分辨率相同。1024 X 1366如果我修复了这个分辨率,它将影响第一代和第二代。

if(Ti.Platform.displayCaps.platformHeight === 1366){
}

此代码导致其他iPad Pro一代的问题。

jchrr9hc

jchrr9hc1#

Titanium在Ti.Platform命名空间中提供了平台标识属性,您可以将其用于代码中的条件分支。
如果使用Ti.Platform.model,它返回模型值,但它有一些Map来理解确切的模型。https://docs.appcelerator.com/platform/latest/#!/API/Titanium.Platform-property-model
以下是Map列表:

["iPod5,1": "iPod Touch 5",
"iPod7,1": "iPod Touch 6",
"iPhone3,1": "iPhone 4",
"iPhone3,2": "iPhone 4",
"iPhone3,3": "iPhone 4",
"iPhone4,1": "iPhone 4s",
"iPhone5,1": "iPhone 5",
"iPhone5,2": "iPhone 5",
"iPhone5,3": "iPhone 5c",
"iPhone5,4": "iPhone 5c",
"iPhone6,1": "iPhone 5s",
"iPhone6,2": "iPhone 5s",
"iPhone7,2": "iPhone 6",
"iPhone7,1": "iPhone 6 Plus",
"iPhone8,1": "iPhone 6s",
"iPhone8,2": "iPhone 6s Plus",
"iPhone9,1": "iPhone 7",
"iPhone9,3": "iPhone 7",
"iPhone9,2": "iPhone 7 Plus",
"iPhone9,4": "iPhone 7 Plus",
"iPhone8,4": "iPhone SE",
"iPhone10,1": "iPhone 8",
"iPhone10,4": "iPhone 8",
"iPhone10,2": "iPhone 8 Plus",
"iPhone10,5": "iPhone 8 Plus",
"iPhone10,3": "iPhone X",
"iPhone10,6": "iPhone X",
"iPhone11,2": "iPhone XS",
"iPhone11,4": "iPhone XS Max",
"iPhone11,6": "iPhone XS Max",
"iPhone11,8": "iPhone XR",
"iPhone12,1": "iPhone 11",
"iPhone12,3": "iPhone 11 Pro",
"iPhone12,5": "iPhone 11 Pro Max",
"iPad2,1": "iPad 2",
"iPad2,2": "iPad 2",
"iPad2,3": "iPad 2",
"iPad2,4": "iPad 2",
"iPad3,1": "iPad 3",
"iPad3,2": "iPad 3",
"iPad3,3": "iPad 3",
"iPad3,4": "iPad 4",
"iPad3,5": "iPad 4",
"iPad3,6": "iPad 4",
"iPad4,1": "iPad Air",
"iPad4,2": "iPad Air",
"iPad4,3": "iPad Air",
"iPad5,3": "iPad Air 2",
"iPad5,4": "iPad Air 2",
"iPad6,11": "iPad 5",
"iPad6,12": "iPad 5",
"iPad7,5": "iPad 6",
"iPad7,6": "iPad 6",
"iPad2,5": "iPad Mini",
"iPad2,6": "iPad Mini",
"iPad2,7": "iPad Mini",
"iPad4,4": "iPad Mini 2",
"iPad4,5": "iPad Mini 2",
"iPad4,6": "iPad Mini 2",
"iPad4,7": "iPad Mini 3",
"iPad4,8": "iPad Mini 3",
"iPad4,9": "iPad Mini 3",
"iPad5,1": "iPad Mini 4",
"iPad5,2": "iPad Mini 4",
"iPad6,3": "iPad Pro (9.7-inch)",
"iPad6,4": "iPad Pro (9.7-inch)",
"iPad6,7": "iPad Pro (12.9-inch)",
"iPad6,8": "iPad Pro (12.9-inch)",
"iPad7,1": "iPad Pro (12.9-inch) (2nd generation)",
"iPad7,2": "iPad Pro (12.9-inch) (2nd generation)",
"iPad7,3": "iPad Pro (10.5-inch)",
"iPad7,4": "iPad Pro (10.5-inch)",
"iPad8,1": "iPad Pro (11-inch)",
"iPad8,2": "iPad Pro (11-inch)",
"iPad8,3": "iPad Pro (11-inch)",
"iPad8,4": "iPad Pro (11-inch)",
"iPad8,5": "iPad Pro (12.9-inch) (3rd generation)",
"iPad8,6": "iPad Pro (12.9-inch) (3rd generation)",
"iPad8,7": "iPad Pro (12.9-inch) (3rd generation)",
"iPad8,8": "iPad Pro (12.9-inch) (3rd generation)",
"AppleTV5,3": "Apple TV",
"AppleTV6,2": "Apple TV 4K",
"AudioAccessory1,1": "HomePod",
"i386": "32 bit Simulator",
"x86_64": "64 bit Simulator"
]

参考资料:如何在iOS上获取设备品牌和型号?
我们可以编写代码来检测模型,如:
当在虚拟设备或xcode中的模拟器上运行时,它返回“iPad 8,5(Simulator)”,当实际设备上运行时,它返回“iPad 8,5”

if (Ti.Platform.model === "iPad8,5 (Simulator)" ||
Ti.Platform.model === "iPad8,5"){
return true;
}
else {
return false;
}

此属性不仅与iOS有关,它适用于所有类型的设备。我只提到了具体的iOS。
帮助由@miga完成
更新的列表可以在这里找到:https://www.theiphonewiki.com/wiki/Main_Pagehttps://gist.github.com/adamawolf/3048717
获取设备ID的步骤:
点击设备->转到相应的页面x1c 0d1x

相关问题