Widgets stopped working after building with Xcode 14

Hello there.

In our app we have several different size widgets, small and medium ones. Everything was fine with iOS 15 and even with iOS 16, while the app was built with Xcode 13. But then we switched to building with Xcode 14, some of widgets stopped working on iOS 16 (other iOS version starting from iOS 14 works well).

Some of them are stuck with placeholder image and they are not updated even if the app is launched. I tried reinstalling the app, removing and adding the widget - nothing works.

The same build, if it is built with Xcode 13, shows widgets working, and as soon as the app is launched on the same device with Xcode 14, widget turns into a placeholder and won't change back.

Update: I tried to debug widget if it has problems with data, and everything seems fine. First time the widget is launched, placeholder function gets called once, then the getTimeline is called twice, and it contains the correct data in entry.

Answered by _Ariovist_ in 730337022

Problem solved.

It looks like something has changed either in Xcode, or in iOS 16 (I'm more to Xcode thing), but all in all, the size of images used in Widgets now matters. In iOS 15 and previous Xcode we were using 4 images of ~500 Kb each, and for some users in iOS 16 after building with Xcode 14 it started to cause memory issues, which turns widget into "placeholder mode". Strange, but it didn't affect iOS 14 and 15 users at all.

Reducing the size of those images to ~100 Kb each solved the problem.

For what it's worth we've been seeing customers with the same issue -- installing with Xcode 13.4.1 GM, no issues; using Xcode 14 on the same source code and people either see the placeholder or some other unexpected snapshot.

Frustratingly, there's also no obvious crashes here, and we've locally been unable to reproduce the issue. Perhaps look at surrounding logs in Console.app if you can reproduce locally?

Accepted Answer

Problem solved.

It looks like something has changed either in Xcode, or in iOS 16 (I'm more to Xcode thing), but all in all, the size of images used in Widgets now matters. In iOS 15 and previous Xcode we were using 4 images of ~500 Kb each, and for some users in iOS 16 after building with Xcode 14 it started to cause memory issues, which turns widget into "placeholder mode". Strange, but it didn't affect iOS 14 and 15 users at all.

Reducing the size of those images to ~100 Kb each solved the problem.

I did what was suggested here reducing the image and also compressing but doesn’t work on iOS 16 (iPhone 12 and iPad Air 4). Any other ideas ? Below the code used:


extension WidgetContent {
    
    var image: Image? {

        guard let picData = self.pic, let uiImage = UIImage(data: picData) else {
            return nil
        }
        let targetWidth = uiImage.size.width
        let targetSize = CGSize(width: targetWidth, height: uiImage.size.height * targetWidth / uiImage.size.width)
        guard let resizedImage = uiImage.resized(toSize: targetSize) else {
            return nil
        }
        var compressionQuality: CGFloat = 0.7
        var imageData = resizedImage.jpegData(compressionQuality: compressionQuality)
        while imageData?.count ?? 0 > 100 * 1024, compressionQuality > 0.1 {
            compressionQuality -= 0.1
            imageData = resizedImage.jpegData(compressionQuality: compressionQuality)
        }
        guard let compressedImage = UIImage(data: imageData ?? Data()) else {
            return nil
        }
        return Image(uiImage: compressedImage)
    }
}

Widgets stopped working after building with Xcode 14
 
 
Q