Building Titanium Apps For HomePod


0 Flares

0 Flares


×

On February 9, 2018, Apple released HomePod, a “connected speaker” that plays Apple Music, and streams audio using AirPlay — all controlled with just your voice and Siri.

On HomePod, you can also use Siri with iOS apps that implement SiriKit for intents such as Messaging, Lists, and Notes & Tasks. HomePod will recognize these requests and route them to the relevant application extension installed on your paired iOS device.

For example, with Things installed on my iPhone, I can say to HomePod, “Hey Siri, add ‘write a blog post’ to Things” and Siri will add a new item to my Things Inbox.

To get started enabling SiriKit with your Titanium apps, there are a few steps you have to follow and luckily there’s a simple guide that will take you through the process and even a demo application you can try too.

Following the guide, you’ll create a Titanium app and SiriKit extension that demonstrates the Messaging Intent on iOS and HomePod.

Here’s a summary of the steps:

  1. Create a new Titanium app or use an existing one
  2. Using Xcode, create a blank app and Siri Intent extension and copy this into the Titanium project
  3. Add some entries into the TiApp.xml file
  4. In the Apple portal, create a wildcard app ID for your Titanium app and another for the extension with the SiriKit service enabled for both
  5. Add Siri permissions to the TiApp.xml file
  6. Create an entitlements file
  7. Build the app to a device

If this all sounds too simple, don’t worry — the guide will take you through the entire process. When you finish, you’ll have an app installed that implements an example of the messaging intent, so it’ll work if you say “Hey Siri, send a message with name-of-your-app”.

SiriKit takes care of asking you any required information, so in this case the recipient and the message content, and will ask you to confirm before “sending”.

It’s pretty cool installing an application on your iOS device and seeing it work so quickly — but even better is seeing it work seamlessly with HomePod.

The demo app isn’t a fully working example — it’s implementing the template you need to get the basics of an intent handler working. In order to actually send the message, or reconcile recipients, you’ll need to add some Swift or Objective-C code to the extension, which will take care of calling any remote APIs or accessing local device data or contacts.

I found the example code really informative and was able to set up examples for Tasks and Workouts pretty easily using it as a template.

Typically, a parent application would never be opened — the extension would be doing all the work. So for task-based intent, the extension would submit the tasks to the server, and the next time the parent app fetches data, it would sync and download them.

In real-world applications, there may be the need to launch or switch to the parent application from the extension — this might be the case if you want to use the Workout Intent where there is an option to continue the request in the app. In this case, Siri will tell the user they need to open the app. Once they do, a Titanium app can pick up the intent details using a continueactivity event handler:

Ti.App.iOS.addEventListener('continueactivity', function(e){  
	// e contains the intent type, userinfo etc.
	console.log(e)
});

There are other ways to send data between your extension and parent app. You could set them both to be in the same app group and then write directly to UserDefaults local storage in Swift or Objective-C from the extension, picking up the data in the Titanium app using the Ti.App.iOS.UserDefaults module.

Alternatively, you can also use modules like Ti.Wormhole which wraps MMWormhole and allows an app and extension in the same app group to share data and communicate via events.

There are several other Siri Intents to try too, including VoIP, Payments, Visual Codes, Photos, Ride Booking, Car Commands, Car Play and Restaurant Reservations – so it’s worth playing around with the demo app to add some of these to your app.

I was able to add the Task and Workout Intents to the same extension pretty quickly, and use Siri on both the iPhone and HomePod to create new Tasks.

I’d love to know your thoughts on SiriKit and if you’re building apps in Titanium that use voice recognition or control, so please drop your comments in the form below.

Happy coding!


0 Flares



Twitter


0








Facebook


0








Google+


0








LinkedIn


0








Email


--






0 Flares


×

Sign up for our blog!

computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×