Python | 获取iOS设备信息的轻量级框架

栏目: Python · 发布时间: 8年前

内容简介: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设备信息的轻量级框架


以上所述就是小编给大家介绍的《Python | 获取iOS设备信息的轻量级框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

模糊数学基础及实用算法

模糊数学基础及实用算法

李鸿吉编 / 科学出版社 / 2005-1 / 55.00元

本书开发了模糊数学常用的计算机程序,并以大量的算例系统地介绍了模糊数学的实用算法。本书可以作为模糊数学的应用程序包,在详细解释源代码的同时,对应用程序开发所用到的Visual Basic 6.0方法做了系统介绍,其目的是为读者做进一步的自主开发提供便利。本书所提供的源程序可以作为读者自主开发的素材。本书配有光盘,分章节提供程序源代码。 本书可以作为大专院校、培训班的教学参考书。对需......一起来看看 《模糊数学基础及实用算法》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具