Refreshing AppIntentRecommendation or IntentRecommendation

In my watch app the AppIntentRecommendation that is returned by func recommendations() needs to be updated after the app is launched.

Problem: The information that I need to return a list of AppIntentRecommendation is not available when the app is first installed, so I return a "dummy" AppIntentRecommendation initially. After the app is launched for the first time and user has signed in, I can update the AppIntentRecommendation in func recommendations() but watchOS does not update the list of widgets presented as complications.

    func recommendations() -> [AppIntentRecommendation<ConfigurationAppIntent>] {
        // Create an array with all the preconfigured widgets to show.
        let defaults = UserDefaults.init(suiteName: "group.myApp")!
        guard let names = defaults.dictionary(forKey: "names" as? [String:String] else {
            return [AppIntentRecommendation(intent: .Demo, description: "Demo")]
        }

        var recs = [AppIntentRecommendation<ConfigurationAppIntent>]()
        for (idx, name) in names() {
            let rec = ConfigurationAppIntent()
            rec.order = idx
            rec.carName = name
            rec.action = nil
            recs.append(AppIntentRecommendation(intent: rec, description: "name") )
        }
        return recs
    }
}

Replies

You can update the recommendations by calling: WidgetCenter.shared.invalidateConfigurationRecommendations()

  • Does WidgetCenter.shared.invalidateConfigurationRecommendations() work on IntentTimelineProvider? For some reason it doesn't refresh recommendations on my Apple Watch app

  • invalidateConfigurationRecommendations is designed to refresh pre-configured intent configurations by calling the recommendations() function. With a watch app + watch extension, this worked perfectly on watchOS 9, but no longer worked on watchOS 10. Thanks [https://developer.apple.com/forums/profile/developer555), I got it working again by converting my project into a single watch app, with no extension

Add a Comment