美文网首页
iOS 获取设备型号,新增2020年新款iPad

iOS 获取设备型号,新增2020年新款iPad

作者: 回眸月 | 来源:发表于2020-04-03 15:57 被阅读0次
    class func getDeviceInfo() -> (model: String) {
            if let bundlePath = Bundle.main.path(forResource: "DeviceInfo", ofType: "plist") {
                let dicData = NSDictionary(contentsOfFile: bundlePath) as! Dictionary<String, Any>
                var systemInfo = utsname()
                uname(&systemInfo)
                let platform = withUnsafePointer(to: &systemInfo.machine.0) { ptr in
                    return String(cString: ptr)
                }
                guard let plat = dicData[platform] else {
                    return ("iPhone")
                }
                return (plat as! String)
            }
            return ("iPhone")
        }
    

    DeviceInfo.plist文件可见链接

    相关文章

      网友评论

          本文标题:iOS 获取设备型号,新增2020年新款iPad

          本文链接:https://www.haomeiwen.com/subject/goohphtx.html