How to send message from widget to iOS app - ios

I'm implementing a widget extension with 3 buttons. These buttons are meant to trigger a method in my iOS app. Is this possible? I know you can share data with UserDefaults but I want to trigger a function right from the widget.

The best way to do it (and the way Apple suggests) is to create an embedded framework with all the common code and methods you need your main app and your widget to share and import that framework to both targets.

Related

iOS - How to pass string from main app to widget without using app group

As title, have any idea let widget get main app data?
As I know using App group to save & load the same suite userdefault.
Does have another way to achieve this feature?
Thanks.
AFAIK as you just mentioned the App groups is the way to go when sharing content between your main App and your widget.
Apple is really restrict about user data safety, and don't think there is there any other way to share content without using the app group as we can see on their documentation available here (Sharing Data with Your Containing App)
Something that would try is using a local notification I think this might work to trigger a local notification to your extension and handle the string on the other side :)
More details available here

How to integrate Siri with flutter application?

I want to integrate Siri in my flutter app for iOS. When the user asks a particular question,
Siri must get the output from the app and execute a function in the app. How can I achieve this?
any help will be appreciated.
In order to achieve this you will need the following:
Create your intent definition file in XCode
Add the Intents extension target to your Xcode project
Configure the Flutter extension home widget
https://pub.dev/packages/home_widget
Add app groups capabilities to both your Runner target and the Intents target make sure to use the same group id
Initialize the App on the flutter side with the same group id
Save the data that your Siri intent would need using the home widget extension methods
Use the saved data reading from UserDefaults
There are some things to consider here:
Siri's intents are in a different Target because they can run in the background if needed, this is why you cannot have a direct communication line between the intent and flutter (Yet).
Instead what you will need to do is to save in memory some data your user might need when using Siri maybe a user id or API key, if you need to make some HTTP calls you will have to do it from Swift.
This is why we need the home widget extension since Home widgets also use a different target and This extension opens a communication channel using App groups and UserDefaults we could use the same communication channel to send data to our Siri Intent.
Just follow the configuration guide of the HomeWidget extension and add AppGroups capabilities to your runner Target and also to your Siri intent. make sure you use the same group ID in all of them including on the flutter side:
HomeWidget.setAppGroupId('YOUR_GROUP_ID');
Then you can use the extension methods to send and receive data between flutter and swift.

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.

Access code and data in hosting app using today extension

I'm wondering if it's at all possible to access features in the main app using a today extension in iOS 8. For example, can a media player send commands from its extension to the main app without opening the app (I know there is a framework for this but it's just an example)? The only solution I can see is using URIs but the problem is that it will open the app which isn't the behavior I'm looking for.
So for a complete example using the media player:
There is an extension in the today screen that allows you to play/pause using a button.
The user presses the button and the app plays/pauses in the background without leaving the notification center.
Any way to achieve this behavior?
Code can be shared using an embedded framework, however there are some backwards compatibility issues.
Data can be shared using shared user defaults.
Both are explained in the apple docs.

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.

Resources