MAC上提取iOS沙盒文件

214 阅读1分钟

背景

APP调试时,经常需要从iOS手机上,获取APP的日志文件进行分析,XCODE自带的下载整个沙盒的功能体验很差

实现方式

iFunBox

使用现成的工具,下载后可以管理沙盒

优点

  1. 直接安装就能使用,有UI界面

缺点

  1. 不能定制
  2. 实测稳定性较差,经常要退出APP重新启动

ifuse

开源项目 Git仓库: github.com/libimobiled…

优点

  1. 灵活,可以自己用脚本传参,实现定制

缺点

  1. 实测稳定性较差,有时候挂载会失败

ios-deploy(推荐)

开源项目,类似Android的adb Git仓库: github.com/ios-control…

优点

  1. 灵活,可以自己用脚本传参,实现定制,日志获取、解压缩、解密、清除日志等操作一键完成
  2. 稳定性很好

安装

brew install ios-deploy

下载日志

#!/bin/sh


isClear=false

# 包名,根据实际情况修改
bundleId="com.xxx.xxx"


CURRENT_DIR=$(cd $(dirname $0); pwd)
iosContainerPath=$CURRENT_DIR"/ios_container"


index=1
for arg in $*                                          
do
    echo "arg: $index = $arg"  
    if [ "$arg" = "c" ] ;then
        isClear=true
    elif [ "$index" = 1 ] ; then
        bundleId=$arg
    fi

    let index+=1 

done

logDirPath="/Library/Caches/logger"

# 清除日志
if [ "$isClear" = true ] ; then
    echo "isClear true:$bundleId"
    ios-deploy --no-wifi --bundle_id $bundleId --rmtree $logDirPath

    exit 0
else
    echo 'isClear false'
fi

# 清空目录再创建
rm -rf $iosContainerPath

ios-deploy --download=$logDirPath --no-wifi --bundle_id $bundleId --to $iosContainerPath


# 目录文件目录
logFileDirPath=$iosContainerPath"$logDirPath"

echo "logFileDirPath="$logFileDirPath
echo "日志文件路径=$logFileDirPath"
if [ -d $logFileDirPath ];then
    echo "日志文件存在"
else
    echo "日志文件不存在"
    exit 1
fi