Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

iphone - Someone facing issues with widgets not working only on some Apple devices?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...