内容简介:Python | 获取iOS设备信息的轻量级框架
今天接着上一篇 Python | 获取Android设备信息的轻量级框架 ,来讲讲
如何通过 Python 实现一个轻量级的库来获取电脑上连接的iOS设备信息。
这个库只有一个文件,通过封装 libimobiledevice 命令实现,返回的是一个包含所有设备信息的标准json格式的列表方便解析,下面简单介绍一下:
libimobiledevice命令封装
@staticmethod
def get_ios_devices():
devices = []
output = Shell.invoke('idevice_id -l')
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 %s -k ProductType' % udid)
device_type = config[output.strip('\n')]
brand = ''
# -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'] = 'iOS'
dic['os_version'] = output.strip('\n')
dic['rom_version'] = output.strip('\n')
output = Shell.invoke('idevicename -u %s' % udid)
dic['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": "iOS"
}
]
注:有时候会报Couldn’t connect to lockdown这样的错误,执行下面命令即可:
$ brew uninstall ideviceinstaller $ brew uninstall libimobiledevice $ brew install --HEAD libimobiledevice $ brew install ideviceinstaller
这个库我已经上传到Pypi仓库,源码在github: https://github.com/logan62334/python-apptoolkit,点击阅读原文可以访问
以上所述就是小编给大家介绍的《Python | 获取iOS设备信息的轻量级框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
断点:互联网进化启示录
[美]杰夫·斯蒂贝尔 / 师蓉 / 中国人民大学出版社有限公司 / 2014-11-1 / CNY 49.00
一部神经学、生物学与互联网技术大融合的互联网进化史诗巨著。 我们正置身网络革命中。互联网的每一丝变化都与你我息息相关。当科技变得无处不在时,它就会改变你我。在《断点》一书中,大脑科学家和企业家杰夫·斯蒂贝尔将带领读者来到大脑、生物与技术的交汇处,向读者展示生物学和神经学是如何与互联网技术发生联系的;我们是如何通过生物学上的前车之鉴,来预测互联网的发展的;互联网在经历增长、断点和平衡后又会发生......一起来看看 《断点:互联网进化启示录》 这本书的介绍吧!