Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS File Retrieval - NSDocumentDirectory

Tags:

ios

iphone

ipad

I am working on a library with a very verbose logger module that, on iOS, writes xml logs to NSDocumentDirectory in a consistent file tree. I want to come up with a way for the user of this library to easily access these logs.

I know it is simple to programatically retrieve files from this directory, but is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs? I feel like I have seen it somewhere before, something in the manner of extracting the .ipa file and going into the package contents, but I could be wrong.

---------------------------------------------------------EDIT------------------------------------------------------------------

This (Browse the files created on a device by the IOS application I'm developing, on workstation?) is how to do it with Xcode on a device, but I have to assume that there is some way we can create that gets the logs off of a device for a user.

like image 881
dokun1 Avatar asked Oct 18 '22 13:10

dokun1


2 Answers

is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs?

It is possible to expose the Documents directory by enabling iTunes file sharing. When file sharing is enabled through this method, the contents of Documents directory would be visible to the user in iTunes, which can also be exported. The documents would also be visible for export through some third party desktop apps like iExplorer.

Here is the link to Apple documentation. You may also refer this thread to understand how this is done.

like image 150
Vin Avatar answered Nov 15 '22 04:11

Vin


If you're using a simulator (apparently your task doesn't seem to need te real device) you are in luck.

You should go to a folder similar to this one:

/Users/[YOUR_USER_NAME]/Library/Developer/CoreSimulator/Devices/[RANDOM_HASH_YOU_SHOULD_DISCOVER]/data/Containers/Data/Application/[RANDOM_HASH_2_YOU_SHOULD_ALSO_DISCOVER]

Once there, with finder, you'll get the "documents" folder of the simulator and the app you're trying to retrieve your logs from.

You might say: I don't know which 2 RANDOM_HASHES should I go to. Yes, you're right. If you have MANY simulators installed and or being used, it might be tricky to discover which one is the one you're trying to debug. The same thing with your APP, your app will live in another RANDOM_HASH folder, and you should browse them, one by one, and then discover your documents folder.

Someone needed to solve this "mess" and created a Xcode Alcatraz Extension that leads you to the exact live simulator and APP you're debugging in any given moment, and then you don't need to guess which 2 random_hash paths you need to navigate to.

If Xcode + Alcartaz plugin extension manager is somewhat out of your reach, you might need to google it. It's not a difficult process.

PS: That magical Alcatraz Extension is named "XCodeWay" (in case you are brave enough to install Alcatraz onto your copy of XCode).

EDIT: Useful link to get Alcatraz: http://alcatraz.io/ Follow its easy instructions and you're done.

EDIT2: If Xcode cannot be used, then the last question in this other thread might come in handy: Browse the files created on a device by the IOS application I'm developing, on workstation? (Still, an external application in your users machine will be needed )

like image 21
Isaac Avatar answered Nov 15 '22 02:11

Isaac