【widget-iOS14-swift】widget使用自定义的Intent提供动态数据
发表于更新于
广州
开发swift【widget-iOS14-swift】widget使用自定义的Intent提供动态数据
❄️2winter开个坑,大概流程:添加一个Intent的配置后,写一个class继承它,然后实现一个泛型方法提供数据给Intent配置文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
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) } }
|
等有空在写。


❄️2winter
ReactNative FullStack Developer
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ❄️2winter!