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

 鉴于iOS设备型号越来越多,所以把设备型号信息写在一个plist文件里,文件地址,写了一个工具类,使用工具类获取设备信息

class func getDeviceInfo() -> (model: String) {
      if let bundlePath = Bundle.main.path(forResource: "DeviceInfo", ofType: "plist") {
           let dicData = NSDictionary(contentsOfFile: bundlePath) as! Dictionary
           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")
  }

你可能感兴趣的:(ios,xcode,swift)