How to integrate Siri with flutter application? - ios

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.

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's the best way to create a custom sharing method on iOS?

A streaming app that I'm using on iOS has a share button that allows me to hook into the sharing app extension. I'd like to be able to send the URL string that it has to a custom API on my server.
Would I need to create an entire app just to have that custom sharing method, or is there another way?
If that's the only way, how can I get that app on my phone without going through the store?
It seems like when I create, build and install apps through Xcode, Apple intentionally breaks the app after a short while?

How to customise SiriKit intent extension for shortcuts app to ask allow access?

We are allowed to build custom intent for Siri, by extending SiriKit.
Moreover, Apples present how to manage basic integrations and customizations to Siri Shortcuts and Shortcuts app
Link for shortcuts app
Nonetheless, some apps have their own shortcuts UI with a little customization; for instance with the button to allow access for API, how can we do that?
In the documentation presented by Apple, there is no such instruction for how is it possible to customize the UI inside the shortcuts app regarding the custom intent created by my app.
I tried to make custom failure for the Intent response but didn't find the option for API access. Like ↴
However nothing quite similar to the UI presented by Shortcuts App, while attempt to first run trello ↴
These actions are provided by the Shortcuts app itself rather than by Siri intents exposed by another app. Indeed, these actions don’t even need the Trello or Wunderlist apps installed.
This means that Shortcuts can present a different UI.
The UI that it will show for your app is defined by the parameters in your intents file.
You can’t create the same experience for your app, however the user can perform any required authorisation in your app itself and it is reasonable to expect that they have run your app before trying to set up shortcuts that use it.

How to send message from widget to iOS app

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.

How to push different IntentViewController in Sirikit extension based on the Intent type?

I am trying to integrate Sirikit extension into my existing iOS app.
For this, I am going to use two different types of intent.
INSendMessageIntent - to send message from Siri through my app.
INSendPaymentIntent - for making a payment
For both the intent types, I was to use custom & different IntentUI.
But how to push different ViewController in Sirikit extension for based on the Intent type i.e., if I say Make payment using MyWorld then one PayViewController has to be pushed and when I say Send message using MyWorld then MessageViewController has to be pushed.
I want to choose View controller dynamically at runtime based on the Intent type (i.e., INSendMessageIntent or INSendPaymentIntent).
I think you should be able to support more than one function of Siri by creating independent targets. The payments UI is one IntentsUI target, and the messages UI is another one. Info plists for each define which target looks after which type of intent.

Resources