ios – How to list multiple shortcuts in Siri Watch Face like calendar?

[ad_1]

I have an app that has 5 variable points of time every day. I’d like to list those 5 points in the Siri Watch Face list, so the user can plan their day with those 5 points in mind. I’m having a hard time displaying more than 1 shortcut at a time in the Siri platter list.

This is my code:

extension INRelevantShortcut {
    convenience init(for myObject: MyObject) {
        let userActivity = NSUserActivity(activityType: "com.acme.myObject-time.\(myObject.type)")
        userActivity.title = myObject.title
        userActivity.isEligibleForPrediction = true
        userActivity.isEligibleForSearch = true

        #if os(iOS)
        let attributes = CSSearchableItemAttributeSet(itemContentType: UTType.item.identifier)
        attributes.contentDescription = myObject.subtitle
        userActivity.contentAttributeSet = attributes
        #endif

        let cardTemplate = INDefaultCardTemplate(title: myObject.title)
        cardTemplate.subtitle = myObject.subtitle

        self.init(shortcut: INShortcut(userActivity: userActivity))
        self.shortcutRole = .information
        self.widgetKind = "WidgetView"
        self.watchTemplate = cardTemplate

        let dateProvider = INDateRelevanceProvider(start: myObject.dateInterval.start, end: myObject.dateInterval.end)
        self.relevanceProviders = [dateProvider]
    }
}

// On 'onPhase == .active' event in iOS app
var siriShortcuts = [INRelevantShortcut]()

let myObject1 = MyObject(type: a, dateInterval: DateInterval(start: 8am, end: 10am))
siriShortcuts.append(INRelevantShortcut(for: myObject1)

let myObject2 = MyObject(type: b, dateInterval: DateInterval(start: 10am, end: 12pm))
siriShortcuts.append(INRelevantShortcut(for: myObject2)

let myObject3 = MyObject(type: c, dateInterval: DateInterval(start: 12pm, end: 2pm))
siriShortcuts.append(INRelevantShortcut(for: myObject3)

let myObject4 = MyObject(type: d, dateInterval: DateInterval(start: 2pm, end: 4pm))
siriShortcuts.append(INRelevantShortcut(for: myObject4)

let myObject5 = MyObject(type: e, dateInterval: DateInterval(start: 4pm, end: 6pm))
siriShortcuts.append(INRelevantShortcut(for: myObject5)

do {
    try await INRelevantShortcutStore.default.setRelevantShortcuts(siriShortcuts)
} catch {
    debugPrint("Siri shortcuts could not be stored", error)
}

// Info.plist in iOS and watchOS apps
<key>NSUserActivityTypes</key>
<array>
    <string>com.acme.myObject-time.a</string>
    <string>com.acme.myObject-time.b</string>
    <string>com.acme.myObject-time.c</string>
    <string>com.acme.myObject-time.d</string>
    <string>com.acme.myObject-time.e</string>
</array>

This almost works but only displays one platter in the Siri Watch Face which is the closest next one. However, scrolling past this one I’d expect to see the other remaining shortcuts that are left in the day, but there is none. When the one shortcut I see does expire, the next one does show up in the list but is the only one again.

How can I make all 5 shortcuts show up for the day like the calendar shortcuts in the Siri Watch Face. My app is kind of the same concept where there are 5 appointments everyday that I can even predetermine for a week.

Thanks for any help or insights.

[ad_2]

Source link

Leave a Reply

Your email address will not be published.