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

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.

Related

Will sqlite database be port over to iTunes when iphone app got sync

I was wondering whether my app's sqlite database will be transfer over to desktop when user sync the app with iTunes or do I need to do some coding to ensure that it will be transferred?
Please advice. Many thanks.
You can transfer the content of your document directory's document folder contents by adding UIFileSharingEnabled key to your info.plist.
Please check the below image:
After adding this key to your info.plist, when you sync your iPad with iTunes the documents inside the document folder will be listed in iTunes as shown below:
This is a nice tutorial for starting the iTunes filesharing: How to integrate iTunes file sharing
We not only can backup our files on itunes but also in icloud....
this is how the app data is persisted along the the app updation ,ios upgradation....
As you long you put your data files in standard locations within the app's sandbox and you don't explicitly flag the file as a file that shouldn't be backed up, then the data files will be backed up to iCloud or iTunes (depending on how the user has setup device backups).
It depends on your file scheme, you can decide which information is necessary and should be backed up and which one should not because it can be easily recreated.
Look for the "Where You Should Put Your App’s Files" section
http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW2

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

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

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

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.

How to retrive Core Data SQL store from Developer's App on the Developer's iPhone

I need a copy of the store that is saved as Core Data sqlite file inside a test app installed on my device.
I know how to get files out of the the simulator at path: ~/Library/Application Support/iPhone Simulator/[Version]/Applications/[AppID]/Documents
...but i need get the .sqlite file from the app on the device itself.
Unless the app itself has file sharing built in, you can't access the documents folder from outside the app. It is a security precaution and part of the sandbox.
Update:
I misunderstood the context of the question. To get files off a developers iPhone, connect the device and open Xcode>Window>Organizer. Select the device in the lefthand pane. In the righthand pane will be a list of applications. Your custom apps will have an arrow next to it. Hit the arrow and you will see "Application Data" hit the down arrow icon and it will let you download the data to folder. That folder will contain the apps Document, Library and tmp folders.
I wrote an application specifically for this to distribute to my customers and testers of my applications when they have problems. iPhoneRescue is free and allows you to get at all of the backup information in your iPhone; this includes any sqlite files.
All the users have to do is find their device backup, find the application, and then save the application files or just a specific file. (This does not work if they have encrypted their backups).