iOS 14 widgets are displayed black on live app

Viewed 2497

I am working on application in which i am using widgetkit extension. i have got one wierd issue like widget is displaying properly on development side, but when i make application live it displays the blank (black) widget to the user.

Screenshot while developing application.

Development

Screenshot while making application live.

Live application

Following is the code of my small widget

import SwiftUI
import WidgetKit
import UIKit

private struct Provider: TimelineProvider {

func placeholder(in context: Context) -> SimpleEntry {
    SimpleEntry(date: Date(), water: drunkGlassesInML.convertInMLfromLTR())
}

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> Void) {
    let entry = SimpleEntry(date: Date(), water: drunkGlassesInML.convertInMLfromLTR())
    completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
    var entries: [SimpleEntry] = []
    let  entryDate = Calendar.current.date(byAdding: .second, value: 10 , to: Date())!
    let entry = SimpleEntry(date: entryDate, water: drunkGlassesInML.convertInMLfromLTR())
    entries.append(entry)
    let timeline = Timeline(entries: entries, policy: .after(entryDate))
    var timer = Timer()
    timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (timer) in
        WidgetCenter.shared.reloadAllTimelines()
        completion(timeline)
    }
}
}
private struct SimpleEntry: TimelineEntry {
   let date: Date
   var water: String
}
2 Answers

Simply Restart iPhone/iPad, After that, go to widgets and check it. It worked for me

This seems to have been fixed on December 3rd/early December. You should update the version of iOS to the latest version, as well as Xcode.

I'm previously had this issue on iOS 14.2 and Xcode 12. I'm now running iOS 14.3 on my iPhone and I'm developing with Xcode 12.3 (12C33)

Related