Different ways to share data between apps — iOS

Data sharing strategies between apps

Dinesh Kachhot
5 min readOct 15, 2017

A good idea is about ten percent and implementation and hard work, and luck is 90 percent. — Guy Kawasaki

As a developer we always have some idea about contribution to community or a business or a product, but to give implement it is all about priority.

You don’t have to be great to start, but you have to start to be great. — Zig Ziglar

It’s about share data between two apps in a single device. Like we want to share Login access, email ids, photos, an event, or a file etc..

Using following ways we can share data between Apps.

UIActivityViewController - iOS 6.0+

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

Open UIActivityViewController and specify the type of data you want to share and will present the activity view controller with apps which support that file type.

To receive files sent to your app using AirDrop, do the following:

The Info tab of your Xcode project contains a Document Types section for specifying the document types your app supports. At a minimum, you must specify a name for your document type and one or more UTIs that represent the data type. For example, to declare support for PNG files, you would include public.png as the UTI string. iOS uses the specified UTIs to determine if your app is eligible to open a given document.

Custom URL Schemes

Native iOS apps and web apps running in Safari on any platform can use these schemes to integrate with system apps and provide a more seamless experience for the user. For example, if your iOS app displays telephone numbers, you could use an appropriate URL to launch the Phone app whenever someone taps one of those numbers. Similarly, clicking an iTunes link launches the iTunes app and plays the song specified in the link. When a user clicks a link, what happens depends on the platform and the installed system apps.

To enable URL Scheme in our app we have to add custom url scheme to info tab. Open safari and type [URL_scheme]://parameter it will open app.

Write a function in AppDelegate class to extract parameters and navigate app accordingly.

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let urlScheme = url.scheme //[URL_scheme]
let host = url.host //red
}

Share Extension — iOS 8.0+

Share extensions give users a convenient way to share content with other entities, such as social sharing websites or upload services. For example, in an app that includes a Share button, users can choose a Share extension that represents a social sharing website and then use it to post a comment or other content.

Share Extension is a type of extension like Today, Action, Custom Keyboard etc. When users choose your Share extension, you display a view in which they compose their content and post it. You can base your view on the system-provided compose view controller, or you can create a completely custom compose view. You can add share extension using add target and select Share Extension in Application Extension section.

Share Extension UI is inherited and from SLComposeServiceViewController.
A Share extension uses its principal view controller’s extensionContext property to get the NSExtensionContext object that contains the user’s initial text and any attachments for a post, such as links, images, or videos.

App Groups

Use a shared app group to share data/files between two/more apps or containing apps. An app group creates a secure container that multiple processes can access. Normally, each process runs in its own sandbox environment, but an app group lets both processes share a common directory.

Allows you to store data to a shared group that other applications that are part of a suite of applications can access. All applications that share keychain access must use the same app ID prefix. Means all the apps that wants to share data must have the same developer team to publish the apps.

Shared Keychain Access — iOS 3.0+

Enabling keychain sharing allows your app to share data in the keychain with other apps developed by your team.

Since iPhone OS 3.0 it has been possible to share data between a family of applications or containing apps(Like extensions). This can provide a better user experience if you follow the common path of free/premium applications or if you have a set of related applications that need to share some common account settings.

A Keychain can be shared across multiple iOS apps if they are published by the same developer and under certain conditions. The most important requirement for sharing Keychain data between two apps is that both apps must have the same app ID prefix.

Custom Pasteboards -iOS 3.0+

An object that helps a user share data from one place to another within your app, and from your app to other apps.
For sharing data with any other app, use the systemwide general pasteboard; for sharing data with another app from your team — that has the same team ID as the app to share from — use named pasteboards.

In typical usage, an object in your app writes data to a pasteboard when the user requests a copy, cut, or duplicate operation on a selection in the user interface. Another object in the same or different app then reads that data from the pasteboard and presents it to the user at a new location; this usually happens when the user requests a paste operation.

My articles are free, but you know you can press the clap👏 button 50 times? The higher you go, the more it motivates me to write more stuff for you guys!

Feeling super generous?

I am Dinesh Kachhot. A creative developer and a logical designer. You can find me on Linkedin or stalk me on GitHub or maybe follow me on Twitter? If that’s too social for you, just drop a mail to dinesh.kachhot@gmail.com if you wish to talk tech with me.

--

--

Dinesh Kachhot

iOS Developer 👨🏻‍💻 Flutter and React Native 💙