You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native:如何检测目标设备是否为iPhone mini机型

检测iPhone mini版本的可行方法

iOS原生开发场景

  • 设备型号标识符匹配:iPhone mini系列有固定的型号标识符,直接读取设备的machine字段对比即可,覆盖已发布的所有mini机型:
    import UIKit
    
    func isIPhoneMini() -> Bool {
        let miniModelIDs = ["iPhone13,1", "iPhone14,4", "iPhone15,5"]
        var systemInfo = utsname()
        uname(&systemInfo)
        let modelID = withUnsafePointer(to: &systemInfo.machine) {
            $0.withMemoryRebound(to: CChar.self, capacity: 1) { ptr in
                String(cString: ptr)
            }
        }
        return miniModelIDs.contains(modelID)
    }
    
  • 屏幕尺寸辅助验证:所有iPhone mini的屏幕逻辑分辨率都是375x812(横竖屏切换时数值互换),结合设备类型可辅助判断,不过建议和型号检测结合避免误判:
    func isIPhoneMiniByScreen() -> Bool {
        guard UIDevice.current.userInterfaceIdiom == .phone else { return false }
        let bounds = UIScreen.main.bounds
        let targetSize = CGSize(width: 375, height: 812)
        return (bounds.size == targetSize) || (bounds.size == CGSize(width: targetSize.height, height: targetSize.width))
    }
    

网页前端场景

  • User-Agent + 屏幕分辨率组合检测:通过JavaScript读取User-Agent确认是iPhone,再匹配mini专属的逻辑分辨率:
    function isIPhoneMini() {
        if (!/iPhone/.test(navigator.userAgent)) return false;
        const { innerWidth: w, innerHeight: h } = window;
        return (w === 375 && h === 812) || (w === 812 && h === 375);
    }
    
    注意:该方法在用户开启分屏、缩放或使用非标准浏览器时可能失效,若需更高准确性,可尝试读取浏览器暴露的设备型号信息(部分浏览器支持)。

内容的提问来源于stack exchange,提问作者Fazal Karim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 13:12:15