iOS 8: options for presenting Action Extensions to users? - ios

After reading the Apple documentation on extensions, it's not clear how Action Extensions get presented to users. The docs mention the Bing translate use case where actions are presented after users tap the Share button. But what if an app, say a chat app, doesn't have a share button? Another example is if the calling app (not the containing app of the extension) presents an option to invoke an Action Extension.
Are these the only two options? In other words, if an app lacks a Share button and doesn't integrate your extension, there's no way to present an Action Extension?

That is correct. Actions are always initiated by the user, and always from system-provided UI.

Extensions are presented as a possible in a UIActivityViewController. The host app provides the UIActivityViewController with the data context. If your extension adheres to this context, it will be available in the list.
If someone writes an app without the UIActivityViewController then they won't be able to use your extension.

May be help you.
Apple provides sample code for ImageInverter: Creating Action Extensions
There are concept for Action Extensions.

Related

How can I open my app directly from the iOS Share Sheet?

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.

What are these copy to app buttons called in swift?

What do you call these copy to app buttons and how to implement them with your own app? Copy to Spark, Viber etc.
They are action / share extensions exposed by other applications to handle a text / photo / url share from any app , you can find them under File->New->Target
That view is a UIActivityViewController.
Those buttons are activities.
The controller is created and then the information is passed in. The activities shown are determined by the type of info passed in (photos, text, url, etc...) and the apps that have registered to handle that type of info.
Have a google for UIActivityViewController to see how you can implement those activities for your own app.

When do extensions included as part of your app show inside an SFSafariViewController UIActivityViewController?

I have two extensions included with my app bundle - an action extension and a share extension. Both of these look for either a URL or a web page as the activation key.
Inside of my app, when an SFSafariViewController is presented and the user presses the share button, both of my extensions show up in the share sheet regardless of whether or not the user has "installed" them outside of the app.
My question: What determines when/if extensions included with the app bundle show up in a SFSafariViewController share sheet displayed inside of the main app?
A bit of background
My thought was to subclass UIActivity and include the implementation of my extensions in the subclasses. Then, I would pass them to a SafariVC using the delegate method of SFSafariViewController so they would show up in the share sheet without the user even knowing they existed.
But, as my question states, my real extensions seem to show up anyways.

Need help on Action Extensions iOS8

I need help on Action Extension, extension feature in iOS8. I am able to create a Action Extension target in my application and is able to see the extension in different Apps say Notes, Photos. Now, i am not able to call the appdelegate and other classes objects in the extension class.
So, how can i import Photos/notes and store it in my application?
You can't use the app delegate because it does not exist in an app extension. Extensions do not run as part of your app, they run independently of it. Moreover, [UIApplication sharedApplication] is specifically not available in app extensions, so the concept of an app delegate is not meaningful to app extensions.
As for how you can import photos and/or notes, that really depends on how your app works. Action extensions can receive data from the host app (Notes or Photos, as you mention) but how you add it to your app depends on your app's design. You get the data via NSExtensionItems, and process it however you need to process it.
Check this out. This might help you.
Appcoda Extension Tutorial
From WWDC 14 Sample Codes.
ImageInverter: Creating Action Extensions
Demonstrates how to use an Action extension with a view controller.

"Open in" feature in UIActivityViewController

I need your help with UIActivityViewController.
I need to present activity controller for the file where, except for default actions, the user will be able to open the file in other apps.
I know how to do this with UIDocumentController, which shows popover with all apps able to open the file.
But how can I show all these apps in UIActivityViewController?
P.S. This behavior can be seen in Apple Mail app, for example.
Look at TTOpenInAppActivity for a way to combine both a UIActivityViewController (for normal sharing), and an 'Open in' button on that which brings up a UIDocumentInteractionController. Pre-iOS 8, that is the best way to manage this.
The function and behavior is different between UIActivityViewController and UIDocumentController.
UIActivityViewController
Presents activities that are pre-defined, you can pass an array to select which ones should be excluded among the default ones that are presented, if you want to add more activities you have to use custom activities, unfortunately these will appear bellow the rest of the activities and even more, the icon will always be gray, your app never loses control since you can use delegates and other stuff to know what is going on on those apps. (Unless you manually make an activity which opens another app)
UIDocumentController
This one asks the system for all the registered applications for a certain file extension, many apps have registered their exclusive extensions which makes it so that this app will be the only one displayed. If you pass an image, you will see all the apps that can handle this file. When using this one your app will lose control since the other app will be opened.
What is your final objective?, If you describe it with more detail we could offer you a better solution.
From what i understand, you should see yourself what type of file the user is trying to open, and then yourself open it with the most suitable one.
Since you cant really emulate what apple is doing, you should handle this problem through your interface, offer the user to "share" or to "open with" for example.
The answer is very simple. There is no way to do it. You cannot add the apps except the defaults into the UIActivityViewControllers.
You are absolutley correct, you can acheive this through the UIDocumentInteractionController.

Resources