I have followed all steps mentioned here for Siri: https://learn.microsoft.com/en-us/xamarin/ios/platform/sirikit/implementing-sirikit?tabs=macos
Also followed: https://developer.apple.com/documentation/sirikit/media/managing_audio_with_sirikit
IntentHandler.cs:
[Register("IntentHandler")]
public class IntentHandler : INExtension, IINPlayMediaIntentHandling, IINAddMediaIntentHandling
{
protected IntentHandler(IntPtr handle) : base(handle)
{
}
public override NSObject GetHandler(INIntent intent)
{
return this;
}
//INPlayMediaIntent
public void resolveMediaItems(INPlayMediaIntent intent, Action<INPlayMediaMediaItemResolutionResult> completion)
{
var mediaItemData = new INMediaItem(identifier: SessionService.LastPlayedEpisode.PodcastId, title: SessionService.LastPlayedEpisode.Title, type: INMediaItemType.PodcastEpisode, artwork: null);
MessagingCenter.Send<object, string>(this, "PlayRecentEpisodeSiriEvent", "ResolveMediaItems");
completion(INPlayMediaMediaItemResolutionResult.GetSuccess(mediaItemData));
}
public void HandlePlayMedia(INPlayMediaIntent intent, Action<INPlayMediaIntentResponse> completion)
{
var userActivity = new NSUserActivity("INPlayMediaIntent");
var response = new INPlayMediaIntentResponse(INPlayMediaIntentResponseCode.HandleInApp, userActivity);
completion(response);
}
public void HandleAddMedia(INAddMediaIntent intent, Action<INAddMediaIntentResponse> completion)
{
var userActivity = new NSUserActivity("INAddMediaIntent");
var response = new INAddMediaIntentResponse(INAddMediaIntentResponseCode.Success, userActivity);
completion(response);
}
}
Now, when I give command to Siri to like: "Play The Daily in myappname" it show this:
So, I am not getting actually how siri will handle Media content to show my app with command. Anyone know:
- How to handle Siri Media Intent in Xamarin.iOS ?
- How to add Siri Support with Xamarin.iOS?
UPDATE: 29 Oct, 2020 - How to play particular episode of Podcast from Playlist is siri?
I am trying to play particular episode of Podcast playlist but it's not working. I have given command to siri like: Play the Overlap by audiochuck from CounterClock podcast in siridemo
here siridemo = my app's name, Overlap = episode name, counterclock = Podcast name.
I am getting only CounterClock in mediasearch.medianame object when control comes to HandleIntent method in appdelegate. So it is possible to achieve this with Siri?
How to fix app hasn't added support for that with siri error?
I have got the solution and it's here.
1. Intent Handler in your IntentExtension project:
First mistake I have done was I have used INPlayMediaIntentResponseCode.Success instead of HandleInApp, which I have corrected here. Why HandleInApp? Hold on :)
2. Now let's Handle it in AppDelegate:
As we have passed HandleInApp as a response in Intent handler's HandlePlayMedia() it will call HandleIntent() method in AppDelegate of your main iOS project. Where the magic will happen.
Output:
Now in MediaSearch.MediaName you will get "Conclusion in Selling Girls of America" as search string.
Happy Coding!