ok, I implemented the new (in beta 3) method: placeholder(with: Context). The widget shows up on the device when I run locally, but when distributed using TestFlight, HomeWidget disappears and cannot be added.
Here his my code for the TimeLineProvider. What am I missing?
public typealias Entry = SimpleEntry
let dict_dummy = ["Gizmo": ["SOC": 89, "ratedRange": 196, "estimatedRange": 185, "unit": "mi", "isTestUser": true]]
public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
var dict = defaults?.dictionary(forKey: Constants.WIDGET_DICT)
if dict == nil {
dict = dict_dummy
}
let entry = SimpleEntry(date: Date(), dict: dict)
completion(entry)
}
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let currentDate = Date()
let refreshDate = Calendar.current.date(byAdding: .minute, value: 10, to: currentDate)!
let dict = defaults?.dictionary(forKey: Constants.WIDGET_DICT)
let entry = SimpleEntry(date: Date(), dict: dict)
let timeline = Timeline(entries: [entry], policy: .after(refreshDate))
completion(timeline)
}
func placeholder(with: Context) -> SimpleEntry {
let entry = SimpleEntry(date: Date(), dict: dict_dummy)
return entry
}
}
@main
struct HomeWidget: Widget {
private let kind: String = "HomeWidget"
public var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
HomeWidgetEntryView(entry: entry)
}
.configurationDisplayName("Stats Widget")
.description("Shows battery SoC and Rated Range")
.supportedFamilies([.systemSmall, .systemMedium])
}
}
Post
Replies
Boosts
Views
Activity
I adopted the new TimeLineProvider and it works locally but not after I distribute it through TestFlight. It's just broken now. Here is my code: https://developer.apple.com/forums/thread/655182?answerId=623190022#623190022
I have implemented the new method in TimeLineProvider but the problem still persists. Seems like a TestFlight problem because the HomeWidget does show up when I install locally.
I even set the policy to .never and the problem persists. Interestingly everything worked with TestFlight before Apple announced that now TestFlight supports HomeWidgets.
				let timeline = Timeline(entries: [entry], policy: .never)
completion(timeline)
OP, you are not alone. This is a TestFlight bug. See this thread: https://developer.apple.com/forums/thread/655393?page=1#623170022
I'm beginning to think that the reason widgets don't show up with TestFlight distribution may not be a bug in TestFlight but a bug in Xcode beta 3. Has anyone tried to submit with Xcode beta 2?
Has anyone tried Xcode beta 4 yet to see if it fixes the problem? The release code does not say anything about this problem. I'm downloading now.
Right Xcode beta 4 still has the problem.
I discovered that to reproduce the problem you don't even need to submit through TestFlight. Just building in Xcode as release (vs debug) causes widgets to disappear.
I have also tried the "dead-code stripping" settings in "build settings" for the target and changing that does not fix the problem either. Given that HomeWidgets is an important feature of iOS 14, it's strange that Apple has not tested this once and even stranger that after filing bug reports against beta 3, they still have not fixed the problem in beta 4.
HomeWidgets cannot have buttons and actions. Yes, I know that you can use the HomeWidget to launch the app and pass a parameter to it do something that you want, but that is not the same thing as what's possible with Today Widgets which does the job without launching the app.
Deprecating Today Widgets without a replacement seems short-sighted.
I've tried MKMapSnapshotter in the TimelineProvider as suggested in the accepted answer, but the completion handler of the start is never called (snapshot is a MKMapSnapshotter object and I have verified that the callback is called when this code runs on the actual app and not the widget TimelineProvider. What am I missing?
let image = snapshot?.image // Image(uiImage: snapshot?.image)
completionHandler(image)
}
The problem is that MKMapSnapshotter.start does not run while the app is in the background and th callback is never called in TimelineProvider. Have you actually tried this? I have tried it and the completionHandler for MKMapSnapshotter.start is never called in TimelineProvider.
If you have found the answer to this question, can you please post here? The authorizationStatus is .notDetermined on the watch and I CMAltimeter uses the iPhone altimeter (instead of the watch altimeter)
One year later this issue still exists. Can anyone tells me if the issue has been solved for them and if there is a workaround?
Specifically, my app has 7 localizations for subscriptions (IAP). The app shows Dutch localization for users whose device is sent to English (including myself).
There is a yellow dot next to some of the localizations.
All in-app purchases have been approved a few days ago.
I had to call Apple developer support to get this problem fixed
Can you let us know how you resolved the issue?