Need help on Action Extensions iOS8 - ios

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.

Related

willBeginSendingToApplication not called when open EverNote or any other extention

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.

iOS call extension from my app

Can I call an app extension (provided from another app) from my app.
Sample Scenario:
I have a photo asset in my app which need to be edited (crop, scale, filter...).
Now I wan't to call an app extension from my app, which supports image editing. The extension starts, the user edit the photo and I get the extension callback with the new image (data or path or something else).
I search around and only the scenarios I found is where someone creates an extension (many tutorials & apple documentations) which can be used in the photos app for example.
Or is it not possible to do that?
Thanks.
I dont think so Inter process communication is not possible in iOS each app is sandboxed

UIApplication.sharedApplication().beginIgnoringInteractionEvents() on Apple Watch

I can not use
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
in WatchKit Extension, I have error:
'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
Is there some alternative ?
The short answer is: No there isn't.
The long answer:
Please keep in mind that the extension is not executed on the watch but on your phone. So if you would call UIApplication.sharedApplication() it would return you the application of the extension on your phone, anyway! Everything you do inside your extension is stuff that manipulates the extension on your phone. The only exception from this are the WatchKit methods. And even they are basically calls that are converted into instructions that are send over bluetooth to tell the watch what to do. At no time you can write code that executes on the watch!
You have no control what so ever about what the watch does with the instructions you send to it. You are basically acting as a server talking to a client and you have no control over the client. You should send as little instructions as possible and once you send them, your task is done, the rest is up to the watch.
That being said, you should carefully plan your UI in a way that you do not need any calls that manipulate the event delivery. You should focus on simple 'if user taps x I do y' interaction.
Another thing to keep in mind is, that your extension can not communicate with your main iOS app. You can create a shared app group between your iOS app and your watch extension to share data between them, however you can not directly communicate with your app. If you want to use parts of your apps logic, extract the module in question into a framework (this has become very easy with Xcode 6) and use the framework in both, your app and your extension.

iOS 8: options for presenting Action Extensions to users?

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.

Action extensions - how will they be incorporated in my app?

Will developers be required to add code to their app to incorporate Action extensions?
Let's say I developed an image editor for iOS - but I want to use Snapseed's Action extensions but not Instagram's. Is that even possible?
No - The extension isn't an "extension" of your app. It's an extension of another app on the O/S the user has the option of utilizing given whatever context your app (the host app) is providing.
Think of it as the user getting to pick what they want to use, not you forcing them to use something. Plus, you have no control over what extension/app the user has installed on their device, so you cannot create a program to even try to depend on that.

Resources