naljin
naljin

Reputation: 611

iOS WidgetKit cannot load certain Image

I have my images Assets.xcassets, and try to load it in my Widget View. To use images in widget too, I already set target membership for widget extension. But the problem is it cannot load certain images (ex. HalloweenOne, HalloweenTwo, HalloweenThree). The size of every images is under 10kb. (All of the images are loaded well in a app.)

Image("HalloweenOne")
    .resizable()
    .aspectRatio(contentMode: .fit)
    .frame(maxWidth: 50)

enter image description here

Upvotes: 6

Views: 2284

Answers (3)

Rock_Artist
Rock_Artist

Reputation: 735

I'm not sure from where is the value, But the Swift Preview hinted me the following:

    ==================================
    
    |  RemoteHumanReadableError
    |  
    |  ArchivingError: imageTooLarge(size: (256.0, 256.0), maximumSize: (106.8, 106.8))

Upvotes: 1

Alexander Naumenko
Alexander Naumenko

Reputation: 106

We have investigated this issue. There are a few reasons:

  1. The image should not be in SVG format, so use jpg or png.
  2. The width of the image should not be >= 1000.

If something is wrong, it will break all the elements of the widget.

Upvotes: 6

YvenChen
YvenChen

Reputation: 81

I also encountered the same problem. After trying many methods, I solved the problem by changing the "Asset Catalog - Compression" on the right to "GPU Smallest Size".

Upvotes: 8

Related Questions