iOS開發(fā)的另類神器:libimobiledevice開源包

轉(zhuǎn)載 望山觀海

簡介

libimobiledevice又稱libiphone,是一個開源包,可以讓Linux支持連接iPhone/iPod Touch等iOS設備。由于蘋果官方并不支持Linux系統(tǒng),但是Linux上的高手絕對不能忍受因為要連接iOS設備就換用操作系統(tǒng)這個事兒。因此就有人逆向出iOS設備與Windows/Mac Host接口的通訊協(xié)議,最終成就了橫跨三大桌面平臺的非官方版本USB接口library。經(jīng)常用Linux系統(tǒng)的人一定對libimobiledevice不陌生,但是許多Windows和Mac用戶也許就不知道了。事實上,它同iTools一樣,都是可以替代iTunes,進行iOS設備管理的工具。因為源碼是開放的,可以自行編譯,所以對很多開發(fā)者而言可以說更為實用。

官方github地址:https://github.com/libimobiledevice/libimobiledevice

最后還有一點,作為一個前Android開發(fā),習慣使用adb命令各種調(diào)試,轉(zhuǎn)了iOS怎么能沒有這種工具,而去使用iTunes和iTools呢?對此零容忍!

快速直接安裝libmobiledevice的方法

  • 在MacOS下安裝可以使用brew,類似Ubuntu中的apt-get
sudo brew update
sudo brew install libimobiledevice
#libimobiledevice中并不包含ipa的安裝命令,所以還需要安裝
sudo brew install ideviceinstaller

  • Ubuntu下安裝需要添加一個新的軟件庫,里面包含了libimobiledevice
sudo add-apt-repository ppa:pmcenery/ppa
sudo apt-get update
apt-get install libimobiledevice-utils
sudo apt-get install ideviceinstaller

常用功能

  1. 安裝ipa包,卸載應用
//命令安裝一個ipa文件到手機上,如果是企業(yè)簽名的,非越獄機器也可以直接安裝了。
ideviceinstaller -i xxx.ipa

//命令卸載應用,需要知道此應用的bundleID
ideviceinstaller -U [bundleID]

  1. 查看系統(tǒng)日志
idevicesyslog

  1. 查看當前已連接的設備的UUID
idevice_id --list

  1. 截圖
idevicescreenshot

  1. 查看設備信息
ideviceinfo

  1. 獲取設備時間
idevicedate

  1. 設置代理(也好像是端口轉(zhuǎn)發(fā)的工具,具體能利用它干啥還沒試過)
iproxy

  1. 掛載DeveloperDiskImage,用于調(diào)試
ideviceimagemounter

  1. 獲取設備名稱
idevicename

  1. 調(diào)試程序(需要預先掛載DeveloperImage)
idevicedebug

  1. 查看和操作設備的描述文件
ideviceprovision list

ideviceinstaller安裝ipa報錯(已經(jīng)支持iOS12)

錯誤1

"Could not connect to lockdownd. Exiting."

出現(xiàn)這個問題一般是因為新版操作系統(tǒng)的通信協(xié)議可能有些微調(diào),參考下面的stackoverflow的帖子,可以通過下面的命令嘗試更新使用最新的libimobiledevice構建版本。

http://stackoverflow.com/questions/39035415/ideviceinstaller-fails-with-could-not-connect-to-lockdownd-exiting

The best solution here is to get the latest libimobiledevice, which has a fix for this particular issue:

brew uninstall ideviceinstaller
brew uninstall libimobiledevice
brew install --HEAD libimobiledevice
brew link --overwrite libimobiledevice
brew install ideviceinstaller
brew link --overwrite ideviceinstaller

錯誤2,進行上面步驟時出現(xiàn)

A recent change to libimobiledevice bumped the constraint on libusbmuxd to >= version 1.1.0. The current usbmuxd homebrew package is version 1.0.10.
As a result, homebrew --HEAD installs of libimobiledevice no longer build without a --HEAD install of usbmuxd.

從意思上看,應該是其中用到的usbmuxd庫更新了,我們系統(tǒng)中的不夠新。那咱們就給他升級一下唄:

brew update
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew link --overwrite usbmuxd

更新了usbmuxd庫之后,可以重復錯誤1中的解決辦法,重新安裝libmobiledevice即可正常使用。

掛載文件系統(tǒng)工具:ifuse

  • ifuse是一個依賴libimobiledevice庫的工具,所以必須首先安裝libimobiledevice

  • 首先去 https://osxfuse.github.io/ 下載fuse for macos的庫。

  • 然后github上clone下載ifuse最新源碼到本地(自己決定放哪):

//cd 到要安裝的目標路徑,然后:

git clone https://github.com/libimobiledevice/ifuse.git

  • 進入clone好的目錄,執(zhí)行:
//將源碼在本機編譯:

./autogen.sh
./configure
make

//執(zhí)行腳本ifuse到系統(tǒng)終端(其實也可以不用,直接去src中運行也可以)
sudo make install

  • 掛載媒體文件目錄:
//注意,此處的掛載點必須要真實存在,需要預先創(chuàng)建好目錄,否則掛載失敗

ifuse [掛載點]

  • 掛載某應用的documents目錄
ifuse --documents [要掛載的應用的bundleID] [掛載點]

//注意,iOS 8.3之后要求應用的UIFileSharingEnabled權限要開啟,否則可能沒有權限訪問,會有如下的錯誤提示

ERROR: InstallationLookupFailed
The App 'com.wsgh.test' is either not present on the device, or the 'UIFileSharingEnabled' key is not set in its Info.plist. Starting with iOS 8.3 this key is mandatory to allow access to an app's Documents folder.

  • 掛載某應用的整個沙盒目錄
ifuse --container [要掛載的應用的bundleID] [掛載點]

  • 獲取bundleID
ideviceinstaller -l

  • 卸載掛載點
fusermount -u [掛載點]

  • 如果是越獄的設備,并且配置好了,可以使用下面命令掛載整個iphone文件系統(tǒng)(暫時沒試過,還沒有開始研究越獄設備)
ifuse --root [掛載點]

  • 詳細說明,可以進入ifuse的github主頁查看原版文檔
https://github.com/libimobiledevice/ifuse
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容