0

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)
}
pawello2222
  • 46,897
  • 22
  • 145
  • 209
EddieF
  • 81
  • 7

1 Answers1

0

Thanks for your help but issue has been fixed after installing 14.5 beta.

EddieF
  • 81
  • 7