libimobiledevice:一個開源包,可讓Linux支持鏈接iPhone/iPod Touch等iOS設備。ios
Git倉庫: https://github.com/libimobiledevice/libimobiledevice.gitgit
ifuse: 也是一個開源包,能夠用來訪問iDevice的工具github
Git倉庫: https://github.com/libimobiledevice/ifuse.gitshell
咱們能夠利用libimobiledevice與ifuse進行shell封裝,輔助實現自動化的測試過程。微信
這裏咱們用來提取iOS設備上APP沙盒中的日誌文件app
MacOS上安裝libimobiledeviceiphone
sudo brew update
sudo brew install libimobiledevice
#libimobiledevice中並不包含ipa的安裝命令,因此還須要安裝
sudo brew install ideviceinstaller
Ubuntu下安裝libimobiledeviceide
sudo add-apt-repository ppa:pmcenery/ppa sudo apt-get update apt-get install libimobiledevice-utils sudo apt-get install ideviceinstaller
1. 獲取設備已安裝app的bundleID工具
ideviceinstaller -l
演示:測試
Jackeys-MacBook-Pro:/ jackey$ ideviceinstaller -l Total: 13 apps com.zhouxi.xiaoailiteios - 小米同窗 20 com.apple.test.WebDriverAgentRunner-Runner - WebDriverAgentRunner-Runner 1 com.apple.store.Jolly - Apple Store 5.0.0.0302 com.apple.clips - 可立拍 4141.1.91 com.apple.mobilegarageband - 庫樂隊 4878.17 com.apple.Keynote - Keynote 講演 5625 com.apple.Numbers - Numbers 表格 5625 com.apple.Pages - Pages 文稿 5625 com.apple.iMovie - iMovie 3709.9.72 com.apple.itunesu - iTunes U 2360 com.sogou.sogouinput - 搜狗輸入法 148198 com.tencent.xin - 微信 6.7.4.44 com.ss.iphone.ugc.AwemeInhouse - 抖音短視頻內測 43006 Jackeys-MacBook-Pro:/ jackey$
2. 安裝ipa包,卸載應用
//命令安裝一個ipa文件到手機上,若是是企業簽名的,非越獄機器也能夠直接安裝了。 ideviceinstaller -i xxx.ipa //命令卸載應用,須要知道此應用的bundleID ideviceinstaller -U [bundleID]
卸載演示:
Jackeys-MacBook-Pro:/ jackey$ ideviceinstaller -U com.zhouxi.xiaoailiteios Uninstalling 'com.zhouxi.xiaoailiteios' - RemovingApplication (50%) - GeneratingApplicationMap (90%) - Complete Jackeys-MacBook-Pro:/ jackey$
安裝演示:
Jackeys-MacBook-Pro:Code jackey$ ideviceinstaller -i QQ音樂\ 8.9.7.ipa Copying 'QQ音樂 8.9.7.ipa' to device... DONE. Installing 'com.tencent.QQMusic' - CreatingStagingDirectory (5%) - ExtractingPackage (15%) - InspectingPackage (20%) - TakingInstallLock (20%) - PreflightingApplication (30%) - VerifyingApplication (40%) - CreatingContainer (50%) - InstallingApplication (60%) - PostflightingApplication (70%) - SandboxingApplication (80%) - GeneratingApplicationMap (90%) - Complete Jackeys-MacBook-Pro:Code jackey$
這裏補充一個: ipa咱們能夠經過itunes來進行下載, 下載完後能夠在iTunnes偏好設置中看到存放目錄
若是鏈接了多部手機須要分別安裝時,請使用UDID指定:ideviceinstaller -u udid -i *.ipa
3. 查看系統日誌
idevicesyslog
4. 查看當前已鏈接的設備的UUID
idevice_id --list
5. 截圖
idevicescreenshot
6. 查看設備信息
ideviceinfo
7. 獲取設備時間
idevicedate
8. 設置代理
iproxy
usage: iproxy LOCAL_TCP_PORT DEVICE_TCP_PORT [UDID]
9. 獲取設備名稱
idevicename
10. 查看和操做設備的描述文件
ideviceprovision list
11. 掛載DeveloperDiskImage,用於調試(這個在個人機器上面不能用, 應該是缺乏什麼東西了)
ideviceimagemounter
12. 調試程序
idevicedebug
若是在運行上面指令出現如下錯誤:
"Could not connect to lockdownd. Exiting."
使用如下方式從新安裝
brew uninstall ideviceinstaller brew uninstall libimobiledevice brew install --HEAD libimobiledevice brew link --overwrite libimobiledevice brew install ideviceinstaller brew link --overwrite ideviceinstaller
從新安裝過程當中若是出現如下錯誤:
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:
brew update brew uninstall --ignore-dependencies usbmuxd brew install --HEAD usbmuxd brew link --overwrite usbmuxd
升級後接着安裝libimobiledevice
安裝方式:
brew cask install osxfuse
brew install ifuse
或者經過官網安裝
1. 安裝好後使用ifuse -h會打印詳細使用說明
Usage: ifuse MOUNTPOINT [OPTIONS] Mount directories of an iOS device locally using fuse. -o opt,[opt...] mount options -u, --udid UDID mount specific device by its 40-digit device UDID -h, --help print usage information -V, --version print version -d, --debug enable libimobiledevice communication debugging --documents APPID mount 'Documents' folder of app identified by APPID --container APPID mount sandbox root of an app identified by APPID --root mount root file system (jailbroken device required) Example: $ ifuse /media/iPhone --root This mounts the root filesystem of the first attached device on this computer in the directory /media/iPhone. Jackeys-MacBook-Pro:Code jackey$
2. 掛在媒體文件目錄:
//注意,此處的掛載點必需要真實存在,須要預先建立好目錄,不然掛載失敗 ifuse [掛載點]
演示:
sudo mkdir /myapp
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse myapp/
Password:
Jackeys-MacBook-Pro:/ jackey$
卸載掛載點
fusermount -u [掛載點]
這個指令在個人電腦上不行, 我改用的sudo umount /myapp
3. 掛載某個應用的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.
演示:
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse --documents com.zhouxi.xiaoailiteios /myapp
Password:
ERROR: InstallationLookupFailed
Jackeys-MacBook-Pro:/ jackey$
報這個錯是由於咱們app沒有開啓文件共享,須要在app的info.plist添加一下字段
咱們再試試
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse --documents com.zhouxi.xiaoailiteios /myapp Password: mount_osxfuse: mount point /myapp is itself on a OSXFUSE volume
這裏報錯的緣由是咱們不能把文件掛在到根目錄, 咱們先刪除以前的掛載
從新掛在到Document目錄下咱們本身的文件夾中
ifuse --documents com.zhouxi.xiaoailiteios /Users/jackey/Documents/Xiaomi/myapp
OK, 此次沒有出錯, 打開Finder進入所在目錄發現myapp文件夾沒有了, 但增長了一個OSXFUSE Volume的目錄
打開裏面就是咱們的Documents目錄
使用umount可卸載
umount /Users/jackey/Documents/Xiaomi/myapp
4. 掛在某應用的整個沙盒目錄
ifuse --container [要掛載的應用的bundleID] [掛載點]
演示:
ifuse --container com.zhouxi.xiaoailiteios /Users/jackey/Documents/Xiaomi/myapp/xiaoailite
打開finder能夠看到整個沙盒目錄都掛在上來了
若是須要自動提取沙盒日誌,這裏咱們能夠寫腳本使用掛在的目錄去獲取裏面的內容
Jackeys-MacBook-Pro:xiaoailite jackey$ pwd /Users/jackey/Documents/Xiaomi/myapp/xiaoailite Jackeys-MacBook-Pro:xiaoailite jackey$ ls Documents Library SystemData tmp Jackeys-MacBook-Pro:xiaoailite jackey$