内容简介: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设备信息的轻量级框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
博客秘诀:超人气博客是怎样炼成的
Darren Rowse、Chris Garrett / 向怡宁 / 人民邮电出版社 / 201005 / 39.00元
作为Web 2.0的新生事物的博客,如今已蓬勃发展,呈燎原之势,业已成为许多人的一种生活方式。中国从事博客写作的人数已达千万级,各类博客网站不可胜数。 然而,为什么有的博客人气鼎盛,拥趸众多,有的博客却门前冷落,少人问津呢?究竟应该怎样写好自己的博客,才能让它吸引更多访客的关注呢?博客网站还能为我做什么呢? 本书的两位作者长期主持知名博客站点ProBlogger.net,指导了成千上万......一起来看看 《博客秘诀:超人气博客是怎样炼成的》 这本书的介绍吧!