gpt4 book ai didi

iOS 14 WidgetKit 不刷新

转载 作者:行者123 更新时间:2023-12-03 09:22:54 25 4
gpt4 key购买 nike

更新:我尝试将时间轴上的策略设置为 .atEnd ,因为只有一个条目。这并没有什么不同。我在 RSS Parser 文件和 AppDelegate 中都尝试过运行 WidgetCenter reloadAllTimeLines方法,它也什么都不做。这让我发疯了,我将不得不使用开发人员支持票来解决这个问题。
我正在慢慢地让我的应用程序为一些 iOS 14 功能做好准备,但不断遇到一个又一个错误,或者(更可能)我没有正确地做事。我正在尽我所能来更新 WidgetKit ,但它不会。 WidgetKit 本身很简单;它显示来自 RSS 提要的最新条目的标题和一些文本。我构建了一个 XMLParser,这段代码在时间轴上运行:

struct Provider: TimelineProvider {
@State private var rssItems:[RSSItem]?
let feedParser = FeedParser()
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), title:"News", description: "News article here", link: "Http://link", pubDate: "The day it posted")
}

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), title:"News", description: "News Article Here", link: "Http://link", pubDate: "The day it posted")
completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> ()) {
WidgetCenter.shared.reloadAllTimelines()

var entries: [SimpleEntry] = []


feedParser.parseFeed(url: "https://fritchcoc.wordpress.com/feed") {(rssItems) in
self.rssItems = rssItems
let currentDate = Date()
let string1 = "Latest News: \n\n"
let string2 = rssItems[0].title

var appendString1 = string1+string2
let entry = SimpleEntry(date: currentDate, title:appendString1, description: rssItems[0].description, link: rssItems[0].link, pubDate: rssItems[0].pubDate)
entries.append(entry)
let refreshDate = Calendar.current.date(byAdding: .minute, value: 2, to: Date())!
let timeline = Timeline(entries: entries, policy: .after(refreshDate))
completion(timeline)

}

}
}
当您第一次安装 WidgetKit 时,它会正确显示最新的新闻项目。但是,我在 RSS 提要中添加了更多条目以对其进行测试,并且它从不更新以显示这些更改,仅显示安装时的新内容。我安装在第二台设备上,在第二台设备上,它确实显示了我为测试添加的新设备,所以我知道它在解析器端和 RSS 本身上工作正常。

最佳答案

iOS 正在处理时间线执行,它不会立即显示。我检查了你的代码,一切似乎都很好。我正在构建一个类似的应用程序,一切正常。我有几乎相同的代码。我有 API HitTest ,它似乎每 10-20 分钟刷新一次 WidgetKit 。至少在我的情况下。
我会把它写成 .atEnd时间线政策。

Each configured widget receives a limited number of refreshes every day. Several factors affect how many refreshes a widgetreceives, such as whether the containing app is running in theforeground or background, how frequently the widget is shown onscreen,and what types of activities the containing app engages in.

WidgetKit does not impose this limit when debugging your widget in Xcode. To verify that your widget behaves correctly, test your app andwidget’s behavior outside of Xcode’s debugger.Source


您是否尝试调试它?你的结果是什么?
你可以尝试测试一些已经 HitTest 的 API,这样你就可以检查 API 被命中了多少次?
编辑:如果您想在添加新闻文章后立即更新您的 WidgetKit ,那么您将需要实现将强制刷新 WidgetKit 的通知。
EDIT2:我发现有时我的 WidgetKit 在初始刷新后不会刷新,并且在屏幕上删除和添加 WidgetKit 解决了这个问题。我认为只有在开发/调试时才会出现这个问题。
EDIT3:删除 WidgetCenter.shared.reloadAllTimelines()来自 getTimeline() .构建项目并运行它。检查控制台日志,您应该在每个请求上打印一些内容。它应该在接下来的几分钟内触发。

关于iOS 14 WidgetKit 不刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64050283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com