I am slowly getting my app ready for some iOS 14 features, but keep coming across bug after bug, or (MORE LIKELY) not doing things correctly on my end. I'm trying every thing in my power to get the widget to update but it will not. The widget itself is simple; it shows the title and some text of the most recent entry from an RSS feed. I built an XMLParser, and this code gets run for the timeline:
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)
}
}
}
When you first install the widget, it correctly shows the latest news item. However, I added some more entries to the RSS feed to test it, and it never updates to show these changes, only whatever is new at the time of install. I install on a 2nd device, and on the 2nd device, it DOES show the new ones that I added for testing, so I know that it is working properly on the parser end, and on the RSS itself.
from iOS 14 Widget Not Refreshing
No comments:
Post a Comment