user1349234
user1349234

Reputation:

How do iPhone apps interact when storing data?

Basically I want to know if apps work and store data independent of one another or if there is a possibility for one app to modify another. Also...

In what folder are apps and their data saved on a phone?

If I modify data locally in an app, will the data be saved in a public place where other apps have access or is it saved to a folder specific to that app?

Upvotes: 0

Views: 674

Answers (3)

Matt S.
Matt S.

Reputation: 1892

The general answer to the first part of this question is: "No". Apps are inherently sandboxed and thus can not communicate between each other. There are a number of exceptions to this:

  1. If you have access to a custom URL scheme for the particular app (Facebook Single Sign On makes use of this).
  2. Opening a document type that is handled by multiple apps on the system (like when opening an attachment in Mail)
  3. If both apps are developed by the same publisher, there are options to use UIPasteboard, iCloud shared Key/Value Dictionaries (only small datasets though), or accessing a shared Keychain Store.

UIPasteboard has some odd behavior as you can have system-wide pasteboards or application specific pasteboards, and there's no guarantee when its going to be cleared or not.

The second question - folder structure - is variable dependent on OS version but generally all applications are stored under the /var directory, followed by a subdirectory structure that utilizes UUIDs to denote the application and then the main app bundle, with the standard app bundle structure (including the Documents directory).

As for modifying data and storage, once again, generally "No". Some apps will utilize UIPasteboard for temporary data storage, but generally you won't know about that inside another application unless you've written the original app.

Upvotes: 1

CGee
CGee

Reputation: 1650

Generally speaking every app has only access to its own working directory and saves all it's data there. So no app does have access to the data of another.

Except a few of Apple's apps like Photos, Address Book, Calendar and so on. App's can use a well defined API to get access to them and do some (controlled) changes. In future iOS versions (beginning with iOS 6) the user will then be asked if a third party application should have access to the data of these few Apple apps.

There's no file-based solution from Apple directly to share data between apps yet (except the clipboard, which is a one-file exception).

Upvotes: 0

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73608

iOS is kinda not that mature in inter-app communication.

Data can be shared between apps using the system clipboard and transmitted over the network through mediums such as email and webservices.

iOS devices also provide a straightforward and well defined method for apps to send messages and data via URLs and filetype handlers. These techniques diverge into two categories:

  1. Custom URL prefixes, e.g. someapp://something/somethingelse?somestuff=whatever
  2. Custom file type handlers by file extension (e.g. *.txt) or by MIME type (e.g. text/plain).

Custom URL prefixes are useful for when two apps have established a specific protocol, while custom file type handlers are much more general, and are designed in a way that allows any app to register itself and participate. This article describes the latter: custom file type handlers for chemical data. If you register your app for a certain filetype it will look like so -

enter image description here

Reg. your second part of question - If I modify data locally in an app, will the data be saved in a public place where other apps have access or is it saved to a folder specific to that app?

As such, each application is restricted in terms of where it can store data on the file system of the device. iOS achieves this by allowing applications to read and write only to their own Documents and tmp directories. Within these two directories the corresponding application can create files and also sub-directories to any required level of depth. This area constitutes the application’s sandbox and the application cannot create or modify files or directories outside of these directories. Check this

Upvotes: 2

Related Questions