这个库只有一个文件,通过封装libimobiledevice命令实现,返回的是一个包含所有设备信息的标准json格式的列表方便解析,下面简单介绍一下:
libimobiledevice命令封装
@staticmethod def get_ios_devices(): devices =[] output = Shell.invoke('idevice_id -1') config_file = os.path.join(os.path.dirname(.__file__),‘ios_mapping.json')with open(config_file,'r') as f: config = json.loads(f.read()) if len(output) > 0: udids = output.strip('\n'). split('\t') for udid in udids: dic=("os_type":'iOS',"uid":udid] output = Shell.invoke('ideviceinfo -u &5 -k ProductType' udid) device_type = config[output.strip('\n')] brand=1 # -1表示找不到 0表示下标 if device_type.find("iPhone") !=-1: brand ='iPhone' elif device_type.find("iPad")!= -1: brand ='iPad' elif device_type.find("iPod")!=-1: brand ='iPod' dic['brand'] = brand dic['model']= device_type output = Shell.invoke('ideviceinfo -u %s -k ProductVersion' udid)dic['os_type'] ='i0S' dic['os_version']= output.strip('\n') dic['rom_version'] = output,strip('\n') output = Shell.invoke('idevicename -u s' udid) dicl'device_name']= output.strip('\n') devices.append(dic) return devices
设备信息数据结构
"uid":"xxxxxxxxxxxxxx1f8a4dcfaac1fd01", "rom_version":"11.0.3", "brand": "iPhone", "device_name":“马飞的iPhone", "os_version":"11.0.3", "model":"iPhone6s", "os_type":"i0S"
注:有时候会报Couldn't connect to lockdown这样的错误,执行下面命令即可:
$brew uninstall ideviceinstaller $brew uninstall libimobiledevice $brew install --HEAD libimobiledevice $brew install ideviceinstaller