4

How can I make my app to appear in Share activity list of Safari, photos, etc.? I would like to let people share link/image or text through my app like they do on facebook.

Facebook/Twitter etc. are available in default UIActivityType list, but how do other apps like Pinterest, Zomato, etc. acheive this?

Dennis
  • 2,119
  • 20
  • 29
optimus
  • 876
  • 1
  • 9
  • 19

3 Answers3

4

The easiest possibility is to use file type association. There are already many tutorials out there, as the concept is already quite established, so I'll just walk you through the main keywords here.

The first thing to determine are the Uniform Type Identifiers (UTI) you want to support. Here is a list of the currently available UTIs from Apple.

Then, in your Xcode project open up the target, and go to the Info tab. There you will find the Document Types entry. Open it up, and hit the plus sign to add a new document type. Specify a name and the UTI you want to support (in this example I picked PDF):

enter image description here

Note that you also need to supply additional document properties. Most tutorials put in (LSHandlerRank, Alternate) as key, value pair, but I did not find any reason for this. It seems to work with (foo, bar) as well.

Next, run your app to make it register on the device.

When you now have a PDF, say an attachment in your Mail app, your app will now appear on the list:

enter image description here

Finally, in your AppDelegate you need to implement the following method:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    NSLog(@"App opened with url %@", url);
    return YES;
}

which is called whenever your app received a PDF. The files will go into a special folder called 'Inbox', and the url will tell you the name of the file that has been supplied.

EDIT

This is a sample console output from my iPhone:

2015-03-19 15:27:32.841 so 29147257[3951:1529409] App opened with url file:///private/var/mobile/Containers/Data/Application/A5723926-F869-49C0-A2AF-756795932B81/Documents/Inbox/first-1.pdf
Dennis
  • 2,119
  • 20
  • 29
1

This is new functionality implemented in iOS 8 and up (and OS X 10.10 and up). It's called Extensions. Extensions lets apps leave their Apple sandbox and access other parts of the OS, including notification center and share sheets. Apple puts it like this:

Starting in iOS 8.0 and OS X v10.10, an app extension lets you extend custom functionality and content beyond your app and make it available to users while they’re using other apps or the system. You create an app extension to enable a specific task; after users get your extension, they can use it to perform that task in a variety of contexts. For example, if you provide an extension that enables sharing to your social sharing website, users can use it to post a remark while surfing the web. Or if you provide an extension that displays current sports scores, users can put it in Notification Center so that they can get the latest scores when they open the Today view. You can even create an extension that provides a custom keyboard that users can use in place of the iOS system keyboard.

There are several different types of extensions, including Apple Watch apps. You can view all those types in the Apple documentation.

To get started building extensions, here are some resources:

0

You will need to use UTImportedTypeDeclarations in info.plist

A good tutorial of this http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app

vichevstefan
  • 898
  • 7
  • 16