13

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
}
Tejas Patel
  • 850
  • 10
  • 26
  • 2
    After rebooting the phone, it starts to show right. I guess it can rely on xcode version and iOS version. Try to update xcode and reupload ipa. – Nike Kov Nov 13 '20 at 22:46
  • 1
    Having this same problem. Works perfectly in the iPhone 11 simulator, but when I install it on my physical iPhone 11, the widgets are just blank black. Edit: I'll let you know if I find any fixes, but otherwise I'm just going to wait for Apple to fix this – Lemon Nov 16 '20 at 23:12
  • @NikKov done all the possible things but still facing same issue. not finding any proper solution. – Tejas Patel Nov 19 '20 at 15:53
  • 1
    @Lemon ok thanks, i will also share if i found any solution for same. – Tejas Patel Nov 19 '20 at 15:53
  • 1
    Update as of 3 Dec, still not working on my iPhone 11, but working on my XCode 12 iPhone 11 simulator perfectly fine. I'll continue to update :) – Lemon Dec 03 '20 at 09:34
  • @TejasPatel Seems to be fixed on my iPhone 11 now. I didn't have to software update either. – Lemon Dec 06 '20 at 07:41
  • hello thanks for reply. did you make any changes in your code in order to display widgets ? – Tejas Patel Dec 06 '20 at 08:04
  • @TejasPatel Nope, no changes at all. I just checked a couple of hours ago and it's working perfectly fine all of a sudden. I haven't even pushed a new version of my development app onto my phone for days now – Lemon Dec 06 '20 at 08:30
  • 1
    It's 2022 and this issue still exists. Getting tired of telling users to go restart their devices just to make the widget load correctly. – Confuseious Feb 01 '22 at 04:37

3 Answers3

2

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

0

Just change appearance of your iphone to normal (Claire) . it's workin for me . but when some users wanna try with other appearance it's still black .

But u can try this idea ^^

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 10 '23 at 06:33
-3

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)

Lemon
  • 1,184
  • 11
  • 33