Back in .NET Conf 2017 The Xamarin team already shared what’s going to be new with Xamarin Forms 3.0 and it actually surprised me. I was expecting some performance improvements, bug fixing and a big upgrade on XAML. But, what they announced focuses on enabling the usage of Xamarin.Forms in more ways and on more platforms. I was really hoping for XAML improvements, maybe add some cascading styling like how CSS works. Maybe sometime in the future, we’ll get it. For now, I’ll just use the XAMLCss by warapa. Anyway if you want to watch all sessions from .NET Conf 2017, you can check it out on Channel9. Going back, I really didn’t expect these new features, but definitely, I love it and really excited to try it out!
That’s why right now, I’m going to show to you one of the exciting features added to the Xamarin.Forms 3.0 that I think you’ll also love. I’m talking about Xamarin.Form’s macOS support.
One of the Xamarin team’s plan is to reach more platforms. That means UWP, iOS and Android are not only platform the Xamarin.Forms will be able to target from now on, they are also bringing macOS, GTK#, Linux and WPF!
With Sirikit developers will finally be able to access Siri in their apps, allowing app users to control third-party apps using Siri. Read on to find out how to build Siri into an app. Second, it allows apps to offer up small snippets of key information — similar to what Google refers to as micro-moments — based on user context. And with support for iOS, watchOS and macOS based apps, Siri Shortcuts can enhance the experience for a broad set of experiences. What the Siri Shortcuts user experience looks like.
You might think that it will be hard and will take a lot of time to integrate your Xamarin.Forms solution into the macOS project, but it’s not. Not at all. You’ll be able to create a native macOS application using your Xamarin.Forms solution using Visual Studio for Mac or Xamarin Studio in just 3 quick steps!
First step: Add a Cocoa App project
Programmatically create toolbar for a window in macOS SwiftUI. Toolbar is an essential UI component for Mac apps. SwiftUI, as of Xcode 11.4, however, does not provide a Toolbar View. Open your project in Xcode. From the menubar select: “File” “New” “Target”. Select “Intents Extension.”. Note that it is not a “Siri Extension,” and you don’t want an “Intents UI Extension,” as that’s something related but different, and click Next. Choose the options for the new target and click Finish. Developers can adopt SiriKit to enable their apps to interact with Siri. In this tutorial, Jayven will walk you through the SiriKit and how you can build an app that communicates with Siri. At the time of this writing, SiriKit is limited to certain kinds of apps. In less than 7 hours, Apple will kick off this year’s WWDC.
Right now, Xamarin.Forms template doesn’t have a Cocoa App initially. So, what you would do is to start Visual Studio for Mac or Xamarin Studio and open your existing Xamarin.Forms solution. Then, add a project into the solution by right-clicking the solution and selecting Add > Add New Existing Project.
You can then select Mac > App > Cocoa App and name it whatever you want, but ideally, the name has a suffix of .macOs.
Second Step: Add the Xamarin.Forms NuGet Package
How To Add Sirikit To Macos App Store
You will have to add the Xamarin.Forms’ latest pre-release nuget package or specifically 2.4.0.282. To do this, right click the Cocoa App project that you just created and select Add > Add Nuget Packages.
Then, search for ‘Xamarin.Forms’ and make sure that the ‘Show pre-release packages’ is ticked. Click ‘Add’ to add Xamarin.Forms nuget package.
You will also need to update the Xamarin.Forms on your shared project and the version should be the same with what the Cocoa app have.
Third Step: Configure the Cocoa App Project
The first thing that you should do with your Cocoa app project is to add the shared project into your Cocoa app as a reference.
Then, open the Info.plist and remove the ‘Main storyboard file base name’ entry (Opened with XCode)
Or just open the Info.plist inside Visual Studio or Xamarin Studio by clicking it and leave the Main Interface blank.
The next one is to update your Main.cs’ Main method to initialize the AppDelegate:
Lastly, update the AppDelegate by changing the NSApplicationDelegate to FormsApplicationDelegate:
Initialize the Cocoa app window within the constructor:
Then inside the DidFinishLaunching method, initialize Xamarin.Forms and load the application:
You can now set your project as the startup project and run your macOS!
Again, in just 3 quick steps, it’s done!
How To Add Sirikit To Macos App Download
This is just a basic walkthrough since this is still on preview. Expect that there are still bugs and not ready for production. Not all nuget packages are compatible and surely, there are lots of UI features still not implemented, but this is a good start. For now, you can send your issues and problems that you encounter in this forum discussion: https://forums.xamarin.com/discussion/93585/preview-xamarin-forms-for-macos/p1
Streaming is available in most browsers, and in the WWDC app.
How To Add Sirikit To Macos Apps
Discover how you can enable Siri summoning for your music or audio app using SiriKit Media Intents. We'll walk you through how to add Siri support to your music, podcast, or other audio service on more of our platforms, including HomePod and Apple TV, so people can start listening by just asking Siri. And learn about new APIs that let you support alternative results, helping people listen more quickly without leaving the Siri interface.
Resources
Related Videos
WWDC 2020
Tech Talks
Download
Hello, and welcome to WWDC.
Hi. I'm Danny Mandel, and welcome to 'Expand Your SiriKit Media Intents to More Platforms.' We've got an exciting mix of SiriKit Media new features and experiences for you this year. We've got a lot to talk about. We're putting a particular emphasis on SiriKit Media Intents in the home this year. As part of that, we'll be opening up to new platforms.
Additionally, we have some new features to discuss.
Finally, we'll finish up with some new ways to make your SiriKit Media experience even faster.
So let's dive right in to the new SiriKit Media platforms. Last year, we made a great experience for you on the go, and this year we're bringing that same great experience to one of the places you listen to music the most-- in the home.
On HomePod, we're using the same media intents and a new cloud playback API to take advantage of the unique characteristics of the HomePod in the Apple Home. You'll want to check out the full developer program details at developer.apple.com/siri.
We're happy to announce that SiriKit Media Intents also now work on Apple TV. In addition to your iOS apps, we know many of you have custom Apple TV experiences, and we wanted to open up SiriKit Media to those apps as well. Now I'll hand it over to my colleague Ryan Klems to give us a demo of the new Apple TV functionality in action. Last year, in iOS 13 and watchOS 6, we introduced SiriKit Media Intent handling for your media applications. This year, we're happy to announce that we've brought that same functionality to tvOS 14. Now you can add Siri support to your applications on the big screen. SiriKit Media Intents allow you to add a wide variety of natural language queries to your application. You can do simple searches: Play music on ControlAudio.
You can ask to play a band: Play the band Khruangbin on ControlAudio.
You can ask to play a song by an artist: Play the song 'Be Kind' by Marshmello and Halsey on ControlAudio...
and many more. So how do you do that? Adding SiriKit Media Intent handling to your tvOS application is done the same way you would add the support to iOS. Please see the 2019 WWDC session, 'Introducing SiriKit Media Intents,' for more information on the steps to add the extension target to your application. Now, let's do a quick recap of how we handle natural language requests in SiriKit Media apps.
The intent handler is the key class in handling SiriKit Media requests, and the key method to implement is resolveMediaItems. resolveMediaItems is where you evaluate the INPlayMediaIntent object that is received by your application and perform a search to turn it into the concrete media item that you want your app to play. After you resolve the media item, your handler will be called, and this will cause your application to be launched so you can begin playback. One difference with tvOS is that the customer is generally only interacting with one application at a time, and as a result, a foreground app launch is likely the more preferred interaction. Unlike on iOS where a background launch is more likely the preferred interaction.
You control this by returning continueInApp from your handle method instead of handleInApp. So, with the same few short steps that we showed you last year, you can add the ability for your application to play audio content through Siri on tvOS. We were very excited to see all the great adoptions of SiriKit Media Intents last year on iOS and watchOS and are looking forward to seeing what you do on tvOS this year. Thanks for that awesome demo, Ryan. Now I want to switch from platforms to new features that make the experience of asking Siri to listen to music even easier. As we work through these examples, we'll be using our example app, ControlAudio, which was introduced at WWDC19.
So let's talk about the new Siri alternatives UI.
So, let's take a look at the current SiriKit Media experience in the new compact Siri UI. We ask to play a song from the album New Me, Same Us. ControlAudio chose a single song to play, and playback begins. There isn't a way to present more information than this, so we're only able to play that one song.
We all know that sometimes we want something slightly different than what starts playing. So we've made it easier to make tweaks on the fly, without having to open the app and disrupt whatever you're doing while on the go.
We do so with the new alternatives UI in SiriKit Media. We can see that someone asked to play that same song, and Siri started playing it for them.
However, we can now also see this new menu that says 'Maybe You Wanted,' and if we tap on it, we are taken to the following UI.
And as you can see here, there are a number of different songs from the same album that someone might have wanted instead of the one that ControlAudio chose. Now we can tap on any one of those options to start playing that instead of the first choice.
And that is the new SiriKit Media Alternatives UI. So how do we make this work? It ends up being quite simple.
In your current resolveMediaItems method, you're probably calling the success with resolvedMediaItem method on INMediaItemResolutionResult. Now, that method is going to return a single media item resolution result.
In order to return multiple items, all you need to do is switch over to the new plural version, successes with resolvedMediaItems, and anything after the first item in the list will show up as an alternative.
So the next question you may ask is how do you handle the taps when someone chooses one of the alternatives? All that happens when someone taps on one of the alternatives is that the media item they've tapped on is set as the media item in the INPlayMediaIntent that is passed to handle. What this means is that you can handle this just as you handle any other INPlayMediaIntent today.
Let's see the code change we need to make in order to get SiriKit Media alternatives working. The first thing we're gonna do is open our intent handler in our sample project, ControlAudio.
And we'll navigate to our resolveMediaItems method.
Currently, we're calling the singular version of the method success with: So let's run the app and see what it does.
Play a song from New Me, Same Us on ControlAudio.
Here's 'Where You Belong' by Little Dragon on ControlAudio. All right, we can see that it started playback, but there are no alternatives.
So let's go back to Xcode, kill the process, and update the method to return multiple media items instead of just a single one.
So now we're calling the plural version of the method successes with: Let's run the app and see what it does this time.
Play a song from on ControlAudio.
'Where You Belong' by Little Dragon now playing on ControlAudio. All right now we have alternatives. Let's go play one.
And I'll play 'New Fiction.' And we can see that it started playing. It's just that easy to get the new alternative support hooked up in SiriKit Media. Now let's talk about some performance improvements that are new to SiriKit Media this year.
Last year, when we launched SiriKit Media Intents, we required the use of an intents extension to adopt your SiriKit Media functionality.
This year, there's a new way to handle SiriKit Media Intents-- in-app intent handling.
In-app intent handling moves all the intent handling stages into your app rather than in an extension. An advantage here is that it avoids a process launch, as you don't need to launch your intents extension and your app to start a background audio session. You only need to launch your app.
However, because it's launching your full app, this could potentially mean a slower Siri response time during the resolve phase. Intents extensions are small, lightweight processes optimized for quick launching, so you will definitely need to tune your full app launch experience to get the same quick response out of it.
One other benefit you could see is that you can start the player warming phase much earlier in your app, since you'll be implementing resolve there. So, if you know you need to kick off network requests to fetch credentials, you can start that at the beginning of resolve and ensure that the player is 100% initialized by the time you get to handle the intent. I refer you to the presentation, 'Integrate Intents with Your App,' to get the full details on in-app intent handling.
For those of you with existing extension-based implementations, we also have a performance boost this year via app pre-warming.
Looking at your existing SiriKit Media implementation, we go through the standard resolve, confirm and handle phases, and then once all those are complete, we issue a background app launch for your app to begin playback.
This does provide for a nice separation of concerns in that the extension can contain all the intent handling logic, and the app can handle the playback logic. However, it can delay important app concerns such as playback engine setup or credential fetching until much later than they need to be.
With app pre-warming, SiriKit will get your app fired up earlier and have playback ready to go once your extension is complete. It's important to note that app pre-warming does require some additional work in your app, so you'll want to work with us to make sure you get it working properly. And last, there are benefits and drawbacks to both in-app intent handling and app pre-warming, so you're going to need to evaluate the pros and cons for your particular implementation to see what works best for you.
We wanted to let everyone in the developer community know that, as the saying goes, we're eating our own dog food.
We're thrilled to have a common framework for our bug fixes, new features, and performance improvements that both you and the Siri team at Apple can benefit from.