iphone transferring files using iTunes, but not allowing user to see all of docs directory? - iphone

It doesn't sound like this is possible, but I will ask anyway.
In my app, I store a lot of images and plists in the documents directory.
I would like to implement a PDF reader in the app that allows users to load their PDFs into the app via iTunes. I do not want the user to be able to see/access the contents of the documents directory since they could cause the app to perform unexpectedly if they messed with these files.
Is this possible, or is it possible to place my plists and images somewhere else?

You'll need to be registered with Apple to see this, but this page should give you the information you need.
You'll need to add a UIFileSharingEnabled key to Info.plist. This will give the user access to the Documents directory of the app, and let them remove or add files.
This tutorial gives an example of how to set up PDF support in an iPad 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 "Share" button

Is there anything like the Android's "Share" button in iPhone?
I am just starting out in iOS development and do not have an iPhone (yet). The idea is to be able to select documents or images saved on the phone and use them in my app. I realize there is an ImagePickerController but that is not what I am looking for. I am also not looking for a third party component, rather something integrated into the OS similar to Android.
Short answer: No.
You can register your app to handle certain file types, and files of those types can then be opened by your app via UIActionSheets that may appear, for example, when you tap and hold on a file in an email. You can also transfer files to your app via iTunes. There's no 'file explorer' type feature in iOS where you can pull up a view of files saved to your phone.
For images, as you mentioned already, you must use UIImagePickerController.
From documentation
Sharing Files with the User
Applications that want to make user data files accessible can do so using application file sharing. File sharing enables the application to expose the contents of its /Documents directory to the user through iTunes. The user can then move files back and forth between the device and a desktop computer. This feature does not allow your application to share files with other applications on the same device, though. To share data and files between applications, you must the pasteboard or a document interaction controller object.
You can read more here:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html%23//apple_ref/doc/uid/TP40007072-CH4-SW7

Sharing files between iPhones and PC

Im looking to see how I can share / export content from my app to allow the content to be imported in the app running on another device.
Something like if you get emailed a pdf file or word file it opens in the correct app when tapped.
I tried using the iTunes sharing approach but that allowed full access to the apps documents folder which allowed the user to mess around with content they should not be allowed to!
The content in the app will be a bundled group of images, text and audio so could be large in size so was thinking of how to transfer easily from within the app to a PC of some file sharing service that would allow the target user to then select this content from within there app and have it imported available to use.
Is this a big ask?
The 1Password app uses DropBox and it seems to work quiet well.

How to protect personal documents in my app for the maximum

I want to protect the user's document downloaded via my app.
- If I store the files in Document folder of iOS, iTunes will read them, right?
- If I store the files in Library or a subdirectory of it, files will be cleaned when the app is upgraded?
- The NSFileManager has a NSFileProtectionKey property. But I'm not sure what exactly it can do to protect the files? Does it can prevent other app from reading the user's files?
Overall, I want the files only can be read in my application, other than iTunes or other jailbreak app.
Thanks alot.
Every app is in a SandBox. It means other apps can't access your app files, even from low-level functions.
So they are quite secure.
You can actually see this with this little app, available from the AppStore:
http://www.eosgarden.com/en/freeware/filesystem/
Apps are located in /var/mobile

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.