I have some apps and most of them have widgets using Coredata fetched data being displayed as expected and the apps have the same Coredata base code for fetching and displaying info into the widgets. Placeholder and snapshot working fine and widgets small, medium and large working as expected on iPhone X, iPhone 7 Plus but not working on iPhone 12 and iPad Air 2.
Below the code being used and the screenshots to give some idea of the issue.
Any ideas?
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [WidgetContent] = []
let managedObjectContext = PersistenceController.shared.container.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Item");
let currentDate = Date()
for hourOffset in 0 ..< 3 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
var entry = snapshotEntry
var results = [Item]()
do { results = try managedObjectContext.fetch(request) as! [Item] }
catch let error as NSError { print("Could not fetch (error), (error.userInfo)") }
let randomIndex = results.randomElement()
let displayPic = randomIndex!.pic
let displayTimestamp = randomIndex!.timestamp
let displayTitle = randomIndex!.title
entry = WidgetContent(date: entryDate, pic: displayPic, timestamp: displayTimestamp!, title: displayTitle!)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
question from:
https://stackoverflow.com/questions/65930730/someone-facing-issues-with-widgets-not-working-only-on-some-apple-devices 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…