Search code examples
iosshellios8filesystemsarchive

How to access application data on an iOS 8 device from terminal?


We are running some tests on our iOS app. The app generates a log file in Library/Caches/Logs/. On an iOS 7 device, we could create an archive of the app, which would contain the app data, and copy the archive to our local machine from the device. Using the ideviceinstaller utility from libimobiledevice (http://www.libimobiledevice.org/), we could then unzip the archive and extract the log file:

# Archive the app and copy to our local machine
ideviceinstaller --udid  $DEVICE_ID --archive ${BUNDLE_ID} -o copy=.

# Unzip the archive and redirect the log file to a file in our current directory
unzip -p ${BUNDLE_ID}.ipa "$(unzip -l ${BUNDLE_ID}.ipa | grep -o "Container/Library/Caches/Logs/${LOG_FILE_NAME}")" > ./${LOG_FILE_NAME}

Unfortunately this no longer seems to work on an iOS 8 device, because of changes to where an app's data is stored in the file system. In particular, apparently app data is no longer included in the app archive: https://developer.apple.com/library/ios/technotes/tn2406/_index.html

We need a way to access this log file on the device, and copy it to our local machine, via a shell script. I'm pretty new to iOS development, so I'm sort of stumped as to how I might do this or whether it's still possible in iOS 8.

Any suggestions would be greatly appreciated and please let me know if anything needs clarification.


Solution

  • I found a utility called ifuse (https://github.com/libimobiledevice/ifuse) which lets me mount the sandboxed root folder of the app and copy the file to my local machine:

    # E.g. ifuse --container com.blah.yourappname <mountpoint>
    ifuse --container ${BUNDLE_ID} ~/mnt
    
    # I found I needed to sleep for a few seconds before trying to access
    # the filesystem, otherwise I'd get "Device not configured" errors...
    sleep 5 
    
    cp ~/mnt/Library/Caches/Logs/${LOG_FILE} ~
    umount ~/mnt
    

    Hope this helps someone else!