开个坑,大概流程:添加一个Intent的配置后,写一个class继承它,然后实现一个泛型方法提供数据给Intent配置文件。
//
// IntentHandler.swift
// bilifansIntent
//
// Created by zl on 2020/10/11.
//
import Intents
import SwiftUI
class IntentHandler: INExtension , UpListIntentHandling{
func provideUpidOptionsCollection(for intent: UpListIntent, with completion: @escaping (INObjectCollection<Ids>?, Error?) -> Void) {
let localUpList = UtilsStore.getUpIdList()
let widgetInitList:[Ids] = localUpList.map { (id) -> Ids in
let ids = Ids(
identifier: "\(id)",
display: "UP:\(id)"
)
ids.id = NSNumber(value: id)
return ids
}
let collection = INObjectCollection(items: widgetInitList)
//传递给小组件
completion(collection, nil)
}
}
等有空在写。