How can I copy files to Documents folder of my app through iTunes - iphone

I saw some apps like GoodReader have this function.
User can copy their documents to a folder of app through iTunes and then use them in app.
What can I do to perform this function.
Thanks!

UIFileSharingEnabled
UIFileSharingEnabled (Boolean - iOS) specifies whether the application shares files through iTunes. If this key is YES, the application shares files. If it is not present or is NO, the application does not share files. Applications must put any files they want to share with the user in their /Documents directory, where is the path to the application’s home directory.
In iTunes, the user can access an application’s shared files from the File Sharing section of the Apps tab for the selected device. From this tab, users can add and remove files from the directory.
This key is supported in iOS 3.2 and later.
from: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

You have to set UIFileSharingEnabled key in the info plist of your app.

Related

which directory should i use for files not available for users?

I have an app for ipad and iphone and since users can download files in there i've enabled UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace in my plist, so users can find the files. (I store them in FileManager.default.url(for:.documentsDirectory,...))
However the app also needs to write texts to files, that shouldn't be accessable for the users. Where should i store those?

Iphone app to be used like usb storage.

I'm wanting to access applications storage via iTunes, where i can save documents and be available in my app.
I have looked all over google, but without a specific name i don't know what I'm looking for.
Some of the app's that use this functionality are VLC & usb Disk; there are many many more.
So I'm asking what the API is called and if anyone knows of sample code or an example.
Essentially, all you have to do is add a boolean UIFileSharingEnabled (YES) key to your app's info.plist. Then the documents added through iTunes will be available in your app's documents directory.
UIFileSharingEnabled (Boolean - iOS) specifies whether the application
shares files through iTunes. If this key is YES, the application
shares files. If it is not present or is NO, the application does not
share files. Applications must put any files they want to share with
the user in their /Documents directory, where
is the path to the application’s home directory.
In iTunes, the user can access an application’s shared files from the
File Sharing section of the Apps tab for the selected device. From
this tab, users can add and remove files from the directory.
This key is supported in iOS 3.2 and later.
Apple's sample code: DocInteraction

access iphone settings

I have saved an musicfile in the iphone path called-"/var/mobile/Applications/92B12BF1-88E1-4FD5-93DC-8311EC3B072A/Music" programmatically .Can I see those files in the iphone ?.Please tell me ,thanks in advance
Yes, you can set in your Info.plist the itunes file sharing property, which will make all files in your app's Documents directory visible to users, both to copy to the desktop and to save files from the desktop to the phone: "Application supports itunes file sharing" and check the box.
Not unless you jailbreak the phone. Other options are
1) store your file under <Application_Home>/Documents, then you can fetch the file from iTunes. You need to set UIFileSharingEnabled key in your Info.plist to YES.
2) run your program in your iOS simulator and examine the file.
92B12BF1-88E1-4FD5-93DC-8311EC3B072A is a GUID, which means it will change.
Second, the only way for you to "view" files outside of your applications sandbox is to be jailbroken.

How does "Open With" some app in iPhone work?

As far as I know, from iOS SDK 3.2, file type handling is added and an iOS application can associate itself with some file type so that other applications can open this kind of file with the application.
Because of the sandbox mechanism in iOS, I wonder when a file in appA is opened with appB, which registered itself with this kind of file, what will happen? Is this file copied to appB and both appA and appB keep a copy of this file? If the answer is yes, is it possible to make appB open the file under appA's document folder? I cannot find any Apple documentation on this.
For example, appA stores a Keynote document in it, if I open this Keynote document with the Keynote app, is it possible to let Keynote app to edit this document in place so that after editing, appA can see the updated document?
Any help is appreciated.
There are a few different questions in here.
When you register your app to handle types of files using the info.plist entry Document types your app will be on the list of apps that are shown when you perform an action with that file (for example tapping a file attachment in an email). Then when your app is launched, the method application:didFinishLaunchingWithOptions: is run as normal, and the launchOptions dictionary will contain the path to the file that was sent to your app. What you do with the file from there is up to you, but it is a copy of the file, not a link to it. So if the user makes changes to the file in the original app they must 'launch' your app again, with the new file.
See here for more info: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions:
You can't access any other app's document folder with the current SDK.
Also, for sharing documents in iTunes (like Pages, Numbers etc), look into the two info.plist entries Document types and UIFileSharingEnabled. (Apples docs: http://developer.apple.com/library/ios/#documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW20) Basically, by setting UIFileSharingEnabled to YES you will expose the /Documents directory of your app in iTunes. Then again it's up to your to show the user once they are back in your app what's in that directory.
Sndbox implemented over standard unix permissions control. All applications are stored in folders with unique name (actually, GUIDs), however owner for them is the same mobile:mobile.
So it looks like they just sends full file path to application which opens the corresponding file.

iTunes Documents Directory in my app

how can I setup my app to accept documents via iTunes, like the Air Sharing or VLC app?
I mean, I want to allow users to get content from the app using iTunes.
Anyone know how?
Thanks
Copied from http://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3_2.html#//apple_ref/doc/uid/TP40009337-SW11.
To enable file sharing for your application, do the following:
Add the UIFileSharingEnabled key to your application’s Info.plist file and set the value of the key to YES.
Put whatever files you want to share in your application’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.