Reputation: 396
Firstly, I'm new at SwiftUI so apologies if I don't know the exact structure or best practice. Secondly, I have been out of program for a number of years but require to better understand the Swift language.
System:
OSX: 11.3.1
XCode 12.5
iPhone: 14.5.1
I'm currently struggling to have a consistent outcome with my code. I am using WidgetKit/WidgetBundle to do some pretty basic stuff like display text. Thats it.
However, I'm being faced with redacted views on the device even though in the simulator it works fine(unredacted). Below is a very basic VStack with Text. I have added unredacted() function which I thought forces the text to be shown.
VStack {
Text("TRANSPONDER")
.kerning(3.0)
.font(.system(size: 20, weight: .light, design: .rounded))
**.unredacted()**
.frame(maxWidth: .infinity, maxHeight: .infinity)
.clipped()
.padding(.all, 0)
.foregroundColor(Color.white)
.background(Color(.displayP3, red: 49.1/255, green: 70.97/255, blue: 85/255))
Spacer()
}
In my TimelineProvider() the below code
struct TransponderGA_TimelineProvider: TimelineProvider {
typealias Entry = TransponderGA_Entry
func placeholder(in context: Context) -> TransponderGA_Entry {
let entry = TransponderGA_Entry(date: Date(),transpondergacode: TransponderCodeGA.init(transponderGACode: "123", transponderGAText: "dswer"))
return entry
}
func getSnapshot(in context: Context, completion: @escaping (TransponderGA_Entry) -> Void) {
let entry = TransponderGA_Entry(date: Date(), transpondergacode: TransponderCodeGA.init(transponderGACode: "1200", transponderGAText: "GA Airspace"))
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<TransponderGA_Entry>) -> Void) {
let currentDate = Date()
let refreshDate = Calendar.current.date(byAdding: .second, value: 10, to: currentDate)!
TransponderGA_Manager.getGATransponder() { (transgacode) in
guard let tcga = transgacode else { return }
let entry = TransponderGA_Entry(date: currentDate, transpondergacode: tcga)
let timeline = Timeline(entries: [entry], policy: .after(refreshDate))
completion(timeline)
}
}
The below result occurs. However, If I use the EXACT same code with another Widget within the widget family it works perfectly.
As you can see it works fine using the same code in another widget this time both on the devices AND the simulator. I'm at a complete loss to why it would work within 1 widget but the other completely hides the content on the device.
As anyone experienced anything like this before?
Upvotes: 2
Views: 1439
Reputation: 396
I can't determine if this was just by chance, however, I was able to fix the issue by adding .unredacted() to ALL widgets within the WidgetBundle.
I found that if 1 of them does not have the function calling unredacted() then it throws them to be redacted automatically.
I guess this makes sense. Everything is redacted unless otherwise specified. It was very odd that it was working normally on the simulator but on the device it would fail. Nevertheless, if anyone else is having the same issue consider .unredacted() on all Widgets within a WidgetBundle.
Upvotes: 3