I have an iOS weather app and am looking to add support for SiriKit Intents.

The basic intent I've set up works correctly with dummy data, but where I'm struggling is with getting my main app / framework to request the forecast from my server and hand it back to the shortcut so I can provide a response in the completion handler:

func handle(intent: GetUVIndexIntent, completion: @escaping (GetUVIndexIntentResponse) -> Void) {

    //TODO: Get the main app to request weather data and hand the result back to Siri.

    completion(GetUVIndexIntentResponse.success(uvIndex: NSNumber(value: 1), burnTimeEstimate: "I'll fix this later! "))

In my main app I handle this by firing off the server request from my model, awaiting a response and using NotificationCenter to communicate the outcome to the View Controller so it can update itself. This sort of pattern doesn't seem like it is suitable for use with Siri Intents though. Are there any alternative patterns/approaches I could use here?

Thank you!

Related posts

Recent Viewed