为什么观察者不使用小部件?

时间:2020-10-09 22:48:39

标签: swift widget rx-swift

这是我第一次使用iOS 14小部件。 我想显示来自观察者的数据。 (RxSwift)

这是我的功能,我不知道是否是获取数据的最佳方法,但是我正在尝试获取信息,但从未执行过。 直到第四行,该功能才起作用,我的意思是,小部件显示“ exito”和“ 787”,但接下来的几行从不执行,因为该小部件从不更新,而且用例也在应用程序上工作。

func getTimeline(in context: Context, completion: @escaping (Timeline<WidgetContent>) -> ()) {
        
        let currentDate = Date()
        let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)!
        var entries: [WidgetContent] = [WidgetContent(date: Date(), name: "exito", cardViewSubtitle: "", descriptionPlainText: "787", releasedAtDateTimeString: "")]
        completion(Timeline(entries: entries, policy: .atEnd))
        
        let contractsDataSource = CoreDataSource.contracts
        let data = ObserveBalanceUseCase(contractsDataSource: contractsLocalDataSource)
        _ = data.execute().subscribe { (balance) in
            let entry = WidgetContent(date: Date(), name: "exito", cardViewSubtitle: "", descriptionPlainText: balance?.availableBalance ?? "", releasedAtDateTimeString: "")
            entries.append(entry)
            
            let timeline = Timeline(entries: entries, policy: .after(refreshDate))
            completion(timeline)
        } onError: { (error) in
            let entry = WidgetContent(date: Date(), name: "error", cardViewSubtitle: "", descriptionPlainText: error.localizedDescription, releasedAtDateTimeString: "")
            entries.append(entry)
            
            let timeline = Timeline(entries: entries, policy: .atEnd)
            completion(timeline)
        }.disposed(by: disposeBag)
    }

为什么用例不起作用?

谢谢

0 个答案:

没有答案