Copy file to/from NSDocumentDirectory during dev - ios

I'm playing with NSDocumentDirectory and saving files on my iPhone. I have created a dictionary and saved it successfully to NSDocumentDirectory and I can re-load it upon re-launch of my app. However, during development I would like to actually browse and copy files to and from NSDocumentDirectory. Is there a way via X-Code or Finder or iTunes to see the contents of my app's NSDocumentDirectory?
The real goal here to move a file generated on my iPhone to my iPad, but starting with copying back and forth from Mac to device would be great!
Any advice is much appreciated.

You can transfer files to / from app's Document directory through the File sharing feature in iTunes. To do so, you have to set UIFileSharingEnabled property to YES in your app-info.plist. See this question if you have problems setting it up.

Download iFunBox. It will allow you to access the IOS file system.
The latest version is here.

IPhoneExplorer is available for Mac and Windows.

Related

iOS Files app won't open my app from another folder

I have an issue while implementing file-based features on my iOS app. I need to open some files inside my app, which I do with an UIDocumentPickerViewController. Everything works great.
Except… when I try to open Files from the iOS 11's Files app. It works as expected when the file is in the "MyAppName" On My iPhone Folder, but if the file is in a random folder on iCloud, nothing. The Files app only tries to display a preview.
Both Application supports iTunes file sharing and Supports opening documents in place are set to YES on my Info.plist. When opening from the Documents folder from Files, AppDelegate's application(_ open inputURL) is called as expected.
Someone has an idea? Thanks!
I use iOS 11.4.1 on my device, and my code is all Swift.
Ok, I found the issue. For Files to open your app with your custom document type, you need to set LSHandlerRank to Owner. I hope it will help someone else :)

How to check persistent storage?

I think I'm being completely stupid but....
I want to check if some of the data has been stored correctly in persistent storage. In the simulator (I don't have an iPhone), I'm currently killing the app, then Xcode throws me an error (rightly so) and I can't reopen the app afterwards. Is there another way of checking the persistent storage?
Thanks a lot in advance
If you are using a real device you can download the contents of the app's folder using Xcode:
Window --> Devices
Select your Device
Select your app
Click the gear icon --> Download Container
The downloaded container will have all the contents stored on the filesystem in your apps folder.
If you are using the simulator you can use a tool like SimPholders to find the app folder on your mac.
If you saved something into UserDefaults you have to look for a file named <bundleIdentifier>.plist. That file will contain all the UserDefaults for your app.

Having a bit of trouble with copying a local file on iOS

Having only worked with Android/web dev before I am having a hard time figuring out where in the world my file should be getting copied to in iOS. After reading the file browser documentation on the iOS developer resource page it says that each app is an "island" which contains its own folder system. If I want to have my user be able to copy a file from my app's sdk to their iOS device, where should I put it?
I downloaded a file browser app from the app store on my iOS testing device but am I right in thinking that there is no global file browsing system?
I am using a Cordova plugin called Asset2sd which works perfectly for me in Android, getting the root storage folder and downloading the file to there. It has no iOS alternative so I'm going to have to figure something else out, I just need to know where to start. Do I have to have the user access my app's internal files somehow? Can I create a folder for them to look in when they download my app? Some documentation or something would be wonderful. I am totally lost.
Thanks!
You're right. Apps don't have access to the global file system. Each app only has access to their own app directory. Here's in-depth information on Sandboxing: https://developer.apple.com/app-sandboxing/
In your app's sandbox, you basically can manage files as you want, i.e. download, copy, move, delete, etc. So you can create a folder Downloads in your apps documents directory and then display the contents of this folder for instance in a table view.
Related documentation/links:
https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html
https://stackoverflow.com/a/6907432/967327
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/iPhoneAppProgrammingGuide.pdf

download the files saved in the ios app

I am designing an ios app which collects the user data and saves the data into a .txt file. I am currently using the sandbox in organizer in xcode to download these files. However, I want the users who do not have xcode to access these files as well.
So are there any ways that I can download these files either via USB, or via FTP to a server, or via iCloud, or via Bluetooth, or via WIFI?
iTunes File Sharing would probably be the easiest method of getting files out of your app. You basically just add the UIFileSharingEnabled key to your app's Info.plist, then save the file to the sandbox's ~/Documents/ directory.
Here's a tutorial if you want a more in-depth discussion of how to use file sharing.
Probably most easiest way is to dump file content to UIPasteboard.

Retrieve files from iOS app Documents folder via command line

For the project I work on, we have to set up performance metrics. The way we do it is that the simulator writes CSV files to a known location. We then retrieve theses files and make graphs out of it. Piece of cake.
We also have these tests running on the device. In that case, the files are created in the Documents directory.
While I can retrieve these files via the organizer, I'd be much more interested in automating that.
How can I retrieve files from an iPhone app via the command line rather than the organizer?
You can actually access the content of your app from your computer, using https://github.com/phonegap/ios-deploy (originally https://github.com/ghughes/fruitstrap) .
It's as simple as :
./ios-deploy --download=/Documents --bundle_id com.mycompany.myapp -2 dest_dir
You can do much more, like listing the content of the app, debug using lldb etc.
You can use iFuse, as part of libimobiledevice
You can not access the documents folder on your iOS device from your computer without itunes.
I run an webserver within my app so i can download the files via http. For zero configuration setup i use Apples Bonjour.
look here:
https://github.com/robbiehanson/CocoaHTTPServer
https://developer.apple.com/bonjour/

Resources