I have a workout app that allows users to track their runs etc. and I’d like to have Siri launch a “New Run” in it. I added the extension, modified the INExtension class to point to my custom class that implements INStartWorkoutIntentHandling. I also added the code for resolving the workout name (although it’s not really necessary for my app) and I gave a standard confirm with .ready. The part I’m missing is, from the “handle” method, how do I launch the app with the “New Run” screen? I understand extensions are separate from their container app and that is the case for SiriKit extensions, but not having done this integration before, I was wondering if there’s any best practice for doing that.
It’s been a while since I played around with SiriKit extensions, so I can’t remember precisely what to do. However, I’ll tell you what I think I remember and hopefully it’ll be of some use to you.
- You have to create an
INStartWorkoutIntent as part of the SiriKit extension.
- Create this with the
INStartWorkoutIntentResponseCode with value
continueInApp. This will get Siri to open your app.
- At the same time, create an
NSUserActivity that provides the info that your app needs to start the workout.
- In your app delegate, implement the
application(_:continue:restorationHandler) method to get your app into the appropriate state given the
NSUserActivity, i.e. to start the workout.
Hope that’s helpful
Thanks @samdavies! I did in fact implement what you described above (after living on StackOverflow for a few hours :]).
In _:continue:restorationHandler, I’m using the following condition to detect the type of activity it has received (I’m only interested in Start and End workout) and I’m successfully going in there. However, for some reason, it’s not invoking the actual workout, but that’s likely a problem in my app logic itself, so I’ll work on that.
I appreciate your response!
f ([ @"INStartWorkoutIntent" isEqualToString:userActivity.activityType])