Post

Replies

Boosts

Views

Activity

Reply to WatchOS what Widgets can have colors?
I have probably found a solution now; the watch faces are buggy asf and sometimes don't update unless you swipe back and forth, keep adding and removing the complication, it may work then. Use @Environment(\.widgetRenderingMode) var widgetRenderingMode (which may show the wrong value for your watch face but after a lot of resetting it finally produces values one can work with)
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’23
Reply to WidgetKit works in Simulator but not on device
Now this should work. "color" is the full color PNG, "alpha" is a transparent PNG. It's blurry on the X-Large watch face but because the watch face requests the wrong resolution. You can do a 2x on the scale however that will break the other complications. Maybe there is a way to know that the Watch requests the icon for the X-Large watch face but I stopped caring, it's stupid to spend so much time on something that simple, not gonna touch this again import SwiftUI import WidgetKit @main struct IconBundle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { IconWidget() InlineWidget() } } struct IconProvider: TimelineProvider { func placeholder(in context: Context) -> IconEntry { return IconEntry(context: context) } func getSnapshot(in context: Context, completion: @escaping (IconEntry) -> ()) { let entry = IconEntry(context: context) completion(entry) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let entry = IconEntry(context: context) let timeline = Timeline(entries: [entry], policy: .never) completion(timeline) } } struct IconWidget: Widget { let kind: String = "IconWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: IconProvider()) { entry in IconView(entry: entry) .containerBackground(Color.clear, for: .widget) } .supportedFamilies([.accessoryCircular, .accessoryCorner, .accessoryRectangular]) .description(Text("Description")) } } struct InlineWidget: Widget { var body: some WidgetConfiguration { StaticConfiguration(kind: "Inline", provider: IconProvider()) { entry in Text("App Title") } .configurationDisplayName("App Title") .description("Description") .supportedFamilies([.accessoryInline]) } } struct IconView: View { @Environment(\.widgetRenderingMode) var widgetRenderingMode let entry: IconEntry var body: some View { imageFor(widgetRenderingMode, entry: entry) .resizable() } } private func imageFor(_ widgetRenderingMode: WidgetRenderingMode, entry: IconEntry) -> Image { var image: UIImage let size = entry.context.displaySize switch widgetRenderingMode { case .fullColor: image = UIImage(imageLiteralResourceName: "color.png") default: image = UIImage(imageLiteralResourceName: "alpha.png") } return Image(uiImage: image.resizeImage(width: size.width, height: size.height)) } struct IconEntry: TimelineEntry { let date = Date() let context: TimelineProviderContext } extension UIImage { func resizeImage(width: CGFloat, height: CGFloat) -> UIImage { let edgeLength = min(width, height) let newSize = CGSize(width: edgeLength, height: edgeLength) UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0) self.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)) if let resizedImage = UIGraphicsGetImageFromCurrentImageContext() { UIGraphicsEndImageContext() return resizedImage } else { return UIImage() } } }
Topic: App & System Services SubTopic: General Tags:
Dec ’23
Reply to Implementing Apple Watch Widget Complications
Did you find a solution to this?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to WatchOS what Widgets can have colors?
I have probably found a solution now; the watch faces are buggy asf and sometimes don't update unless you swipe back and forth, keep adding and removing the complication, it may work then. Use @Environment(\.widgetRenderingMode) var widgetRenderingMode (which may show the wrong value for your watch face but after a lot of resetting it finally produces values one can work with)
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to WidgetKit works in Simulator but not on device
I probably found a solution. Surprise surprise it's another thing not at all documented by Apple. Will update you tomorrow
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to WidgetKit works in Simulator but not on device
Now this should work. "color" is the full color PNG, "alpha" is a transparent PNG. It's blurry on the X-Large watch face but because the watch face requests the wrong resolution. You can do a 2x on the scale however that will break the other complications. Maybe there is a way to know that the Watch requests the icon for the X-Large watch face but I stopped caring, it's stupid to spend so much time on something that simple, not gonna touch this again import SwiftUI import WidgetKit @main struct IconBundle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { IconWidget() InlineWidget() } } struct IconProvider: TimelineProvider { func placeholder(in context: Context) -> IconEntry { return IconEntry(context: context) } func getSnapshot(in context: Context, completion: @escaping (IconEntry) -> ()) { let entry = IconEntry(context: context) completion(entry) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let entry = IconEntry(context: context) let timeline = Timeline(entries: [entry], policy: .never) completion(timeline) } } struct IconWidget: Widget { let kind: String = "IconWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: IconProvider()) { entry in IconView(entry: entry) .containerBackground(Color.clear, for: .widget) } .supportedFamilies([.accessoryCircular, .accessoryCorner, .accessoryRectangular]) .description(Text("Description")) } } struct InlineWidget: Widget { var body: some WidgetConfiguration { StaticConfiguration(kind: "Inline", provider: IconProvider()) { entry in Text("App Title") } .configurationDisplayName("App Title") .description("Description") .supportedFamilies([.accessoryInline]) } } struct IconView: View { @Environment(\.widgetRenderingMode) var widgetRenderingMode let entry: IconEntry var body: some View { imageFor(widgetRenderingMode, entry: entry) .resizable() } } private func imageFor(_ widgetRenderingMode: WidgetRenderingMode, entry: IconEntry) -> Image { var image: UIImage let size = entry.context.displaySize switch widgetRenderingMode { case .fullColor: image = UIImage(imageLiteralResourceName: "color.png") default: image = UIImage(imageLiteralResourceName: "alpha.png") } return Image(uiImage: image.resizeImage(width: size.width, height: size.height)) } struct IconEntry: TimelineEntry { let date = Date() let context: TimelineProviderContext } extension UIImage { func resizeImage(width: CGFloat, height: CGFloat) -> UIImage { let edgeLength = min(width, height) let newSize = CGSize(width: edgeLength, height: edgeLength) UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0) self.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)) if let resizedImage = UIGraphicsGetImageFromCurrentImageContext() { UIGraphicsEndImageContext() return resizedImage } else { return UIImage() } } }
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Ads Attribution with Firebase without IDFA consent
Did you find a solution to this? I also don't want to track anything except for sales on ads. It's a weird choice from Apple that they don't show this in App Store Connect but instead make us rely on the potentially unsafe partners they have
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’23