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?
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):
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:
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
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:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionCreation.html#//apple_ref/doc/uid/TP40014214-CH5-SW1
http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794
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
Related
Update: don't have time yet to test provided answer, but will keep this answer updated as I try different things.
In the iOS 14 Simulator, when I open the share sheet and click their Share Target, the Apple News app is launched immediately and they check if the shared URL has been added to their index.
My question is how are they launching their app immediately without any user interaction?
A gif is worth about 100,000 words: https://giphy.com/gifs/HPzTNyWGDDMVwASQ9z
I would imagine it may be some combination of registering a Universal Link and then programmatically triggering that from the Share Extension View Controller, but I’m wondering if anyone has any better ideas.
A couple of other places I've asked:
Swift Subreddit
iOS Programming Subreddit
This is just an open URL call to a news app. Prior to iOS 14, it was named as copy to app name.
To achieve this you need to specify the supported document type for your application in plist using key CFBundleDocumentTypes.
Refer to apple documentation for more info:
https://help.apple.com/xcode/mac/current/#/devddd273fdd
There is a change in share sheet option listings.
case 1: When your application doesn't support any kind of extension. And have supported document add to plist. Your application will appear in the share sheet for supporting documents. On tap, your application gets an OpenURL call with the URL of the document shared.
case 2: Your application supports share extension or action extension, then your open URL call option for your application will not appear in the share sheet. if the share extension and action extension activation predicate are not satisfied and the document shared is supported by your application that option will appear the same as case 1. (Summary: if share extension or action extension is listed in share sheet then open URL option will not be listed.)
Note: Limitation of openURL call is, it supports only a single URL. For example, you are sharing multiple files, your application OpenURL option will appear. But on tap, your application will receive only one URL.
If your requirement is sharing only a single URL and your application doesn't have a share extension and action extension. Then key CFBundleDocumentTypes is your friend.
We use an LMS calles Canvas by instructure. Our students access the LMS via the iOS app, however we would like to be able to call out from this app to another app (e-book reader).
We just want to be able to select a link which will redirect us to the app.
We have a coder in our staff, and we would really appreciate any advise on how to achieve the above.
You can communicate with URL Schemes between apps Apple Inter-App Communication
And here is Tutorial explaining URL Schemes implementation.
If you have access to the e-book reader app's codebase, this is simple to achieve by specifying a URL Scheme this app may respond to (or, alternatively, if you happen to know what URL Schemes this app supports). Then it will be as simple as calling out a URL of a corresponding format from within the iOS app your students use.
Alternatively, if your app provides access to the documents of some sort, you could look into UIDocumentInteractionController that can add "Open in..." functionality to your app, allowing app users to open a document in an arbitrary app that supports this file format.
I have a feature to open docs in other apps from iPhone and iPad app.
Also a flag is set whether to allow this action or not. Few apps can be white listed.
When any app is chosen to open doc
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
is called.
In this method I can check whether to allow for chosen app or not.
Issue is for Note, Evernote we get two options 1- its extension 2- Open in.
Above method is called for 2 option.
But extensions are launched directly.
I din't found any other delegate method called for this.
Hopefully you figured something out, but my org faced a similar issue and the MDMs we work with don't have an easy solution. We've decided on the following approach.
Always use UIDocumentInteractionController instead of UIActivityViewController
Whenever UIDocumentInteractionController is opened reinit and set the URL to dummy content
Conform to UIDocumentInteractionControllerDelegate and check the application parameter in willBeginSendingToApplication against your whitelist
If application is part of the whitelist then change the value of controller.url to the correct content
The downsides of this approach are that only open-in will work (extensions will always get dummy content) and the user experience isn't great. But if you're building an enterprise app and must prevent data leakage then this is probably the safest way to go.
You can also check out this article for private APIs to hide third-party apps and extensions, mostly in UIActivityViewController:
How to exclude Notes and Reminders apps from the UIActivityViewController?
Unfortunately the way this works seems to have changed between iOS 8 and 9, and again with 10, so it's not optimal. I recommend passing dummy content.
How do you import or display an application inside another application?
It is like, it will be a part of the app where you can use it's functionalities. Maybe in full screen or not in full screen. My thoughts are these are web based and is being opened in a UIWebView to use the functionalities.
Extensions? It's more like "piggybacking".
Here's an example:
https://hub.united.com/en-us/news/web/pages/uber-on-the-united-app.aspx
I'll post an answer regrouping my answer and also #Popeye one that seems valid too.
There may be a few ways to do it, each ones of them may act differently.
The other app offers a public SDK/API/WebServices
As an example, I'll take FaceBook API, that allow you to login giving you a UIViewController (that you can customise), and allowing you to ask for some data through their WebServices (like who are the friends, etc.). You're still inside your app.
The other app offers you a private SDK/API/WebServices
Same as the other one, but it more like a parternship. You're still inside your app.
URL Schemes
The other app gives you a few way to interact with it. They check if the app is installed, and launch it with some parameters, or if not, they may redirect it to the app in the Store, their website, etc. More info about URL Schemes from Apple Doc. You have to check their documentaion to know how to interact with it.
I'm totally new in iOS development. I'm developing an app processing some strings in UItextview. After the process, I want show "Open In.." menu with all applications can receive text values.
To explain more. What I mean is like this in Android http://developer.android.com/training/sharing/send.html
I took a quick look at the link you posted.
Apple enforces a "sandbox" around apps which greatly limits what you can do.
Off the top of my head here are a few ways to do it:
Define a custom URL scheme in each of your apps. One app would open a URL using the other app's URL scheme, and that would open the other app and pass it the URL.
For a family of apps from the same company you should also be able to set up a common base "bundle ID" and use that to read and write shared entries to the keychain. The keychain is limited to fairly short bits of data however. (It's intended for password strings and the like.)
I haven't used it before, but you should also be able to use the UIDocumentInteractionController class to pass a copy of a document between apps. As I understand it, the sending app presents a document and asks the user to pick an app with which to open the document. When the user picks a target app, the system creates a copy of the document in the target app's documents directory and then tells the target app to open it.