download the files saved in the ios app - ios

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.

Related

How to Save video file to iOS Files App using UIDocumentInteractionController

I want to write one or multiple mov/mp4 files to iOS Files App but can not find how to do it with UIDocumentInteractionController. Looking for a sample code to copy files to a subfolder of my app in iOS files app using UIDocumentInteractionController. See sample screenshot to understand what I want.
You will first need to create a File Provider extension for your app if you are storing the files remotely.
If they are only being stored locally on device you can achieve this by (in the Info.plist) either setting the UISupportsDocumentBrowser key, or by setting bother the UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace keys.
As explained in this documentation:
These keys enable other apps to open and edit the contents of your Documents directory in place. Your files also appear in both the Files app and the document browser. For more information, see the UIDocumentBrowserViewController class.

Can a PDF downloaded by my iOS app be viewed by iBooks or any other application?

Right now, the PDFs I download on my app are being stored in the app's document directory and can be retrieved only within the app. Is there any way to store the PDF files in the common documents directory that can be accessed by other apps?
If not, is there a way of storing my downloaded PDFs in other apps' documents directory (let's say iBooks), so that it will always be stored in iBooks.
If there are any ways, please elaborate.
There is no "commun documents directory" on iOS, each App is launched in is own sandbox and cannot access the files from other app directly.
I suggest you to check the iOS File System Basics guide from Apple in order to understand better what's happening behind the scenes.
You can still use an UIActivityController in your code to perform an export of your pdf file to iBooks or any app accepting this kind of file, but it requires some user interaction.

how do you export a file out of iOS when using cordova file plugin?

I'm using https://github.com/apache/cordova-plugin-file on an iOS device and I'm attempting to write files. I can write files ok but according to the iOS file system layout, all of these locations where I write are private.
I'm guessing this is due to Apple's sandbox security model so that each app can only see files within its own bundle. This is different on Android where the cordova.file.externalRootDirectory location is NOT private.
My question is: How do you export this file out of an iOS device?
The file that I'm writing contain a long list of GPS locations captured by the Cordova app I'm running. I can see the file in XCode, under devices, and export the whole container in order to view the file. But there has to be a better way to transfer the file out. Is it possible to transfer a Cordova generated file out of an iOS device to the computer -- maybe through iTunes or iCloud?
I've also tried using cordova.file.syncedDataDirectory and I can write files to that location just fine. But the file doesn't appear in my iCloud account.
You have to use itunes file sharing
File-Sharing Support
File-sharing support lets apps make user data files available in
iTunes 9.1 and later. An app that declares its support for file
sharing makes the contents of its /Documents directory available to
the user. The user can then move files in and out of this directory as
needed from iTunes. This feature does not allow your app to share
files with other apps on the same device; that behavior requires the
pasteboard or a document interaction controller object.
To enable file sharing for your app, do the following:
Add the UIFileSharingEnabled key to your app’s Info.plist file, and set the value of the key to YES.
Put whatever files you want to share in your app’s Documents directory.
When the device is plugged into the user’s computer, iTunes displays a File Sharing section in the Apps tab of the selected
device.
The user can add files to this directory or move files to the desktop.
Apps that support file sharing should be able to recognize when files
have been added to the Documents directory and respond appropriately.
For example, your app might make the contents of any new files
available from its interface. You should never present the user with
the list of files in this directory and ask them to decide what to do
with those files.
So, add the UIFileSharingEnabled to your info.plist and set it to YES
https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/CoreServicesLayer/CoreServicesLayer.html#//apple_ref/doc/uid/TP40007898-CH10-SW30
#jcesarmobile's answer helped me track down that I needed to enable file sharing in iOS. After confirming that I can enable file sharing by modifying the info.plist file in XCode, I found out that you could directly set UIFileSharingEnabled in the config.xml file but it's a bit more tricky because it's not a standard preference.
<gap:config-file platform="ios" parent="UIFileSharingEnabled" mode="replace">
<true/>
</gap:config-file>
After putting this in my config.xml file, it worked.
This is noted in the PhoneGap documentation, but I'll admit that it was really buried and a bit difficult to find.
http://docs.build.phonegap.com/en_US/configuring_config_file_element.md.html#Config%20File%20Elements

How to choose files from iPhone?

In my app I have to upload files to server.
For that I need to view and choose files from my iPhone and iPad. (any kind of files i.e pdf , doc,dock , mp3 etc etc).
How can I get the path for these files and how can I choose them in my application.
Generally in iPhone Where are these files are stored? how we can fetch them in our application?
Is there any thing like UIImagePickerController to pick file from iPhone?
There are classes that allow you to interact with various media types that may be on an iOS based device.
As you mention UIImagePickerController.
For music, you can use a similar class: MPMediaPickerControllerDelegate.
With regard to other arbitrary documents;
There is no device-wide document store, and you cannot access files stored inside another app's app bundle, thus you cannot access saved PDF/doc files. There is no shared place for the user to save such PDFs in the first place. Which is why media libraries have specific APIs to access them because they are device-wide libraries.
The most you can do is register your app as a viewer of PDF documents. This would allow other apps to open a PDF in your app if they use a UIDocumentInteractionController.
Your best option is probably to use File Sharing which will allow your application to own files on the device which can be synced via iTunes.
This will enable you to create your own UI, to present these files from your applications document folder.
Further reading: iOS File System Basics, File System Programming Guide.

Copy file to/from NSDocumentDirectory during dev

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.

Resources