Skk
Skk

Reputation: 198

WidgetKit on watchOS with SwiftUI - view with Image(uiImage:) does not render on watchOS

This is on iOS 16.1 with Xcode 14.1. I have this view here which I wish to use on both iOS 16 Lock Screen as a Lock Screen widget and watchOS 9 as a complication, as .accessoryCircular:

struct ComplicationImageCircularView: View {
    let name: String
    let avatarData: Data
    
    var body: some View {
        if let image = UIImage(data: avatarData) {
            Image(uiImage: image)
                .resizable(resizingMode: .stretch)
                .aspectRatio(contentMode: .fit)
                .widgetLabel(name)
        }
    }
}

The avatar data is downloaded from the provider and passed into this view via the entry and entry view.

This view works just fine on the iPhone's Lock Screen, but on watchOS the complication appears empty.

I tried to make sure that the watchOS complication target to include UIKit, since this view uses UIImage, but that didn't work out.

Upvotes: 2

Views: 836

Answers (1)

Skk
Skk

Reputation: 198

It turns out that my avatarData is an image of a size bigger than 120x120. WidgetKit on watchOS rejects anything bigger than 120x120.

Upvotes: 6

Related Questions