Is Image rendering allowed inside ActivityReportExtension

Versions

  • XCode version: 16.2
  • iOS version: 17.0

Background

I am trying to generate a QR code inside the ActivityReportExtention which encoded the FamilyActivitySelection information. The code is roughly:

Question

  1. Can I create Image inside the ActivityReportExtension? I cannot even render a simple image (not QR code) inside the extension.
  2. How can I debug inside the extension? Logs of the extension are not shown in the console.

Code

A function to generate QR Code

import CoreImage
import UIKit

func generateQRCode(from string: String) -> UIImage? {
    let data = string.data(using: .ascii)
    guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }
    filter.setValue(data, forKey: "inputMessage")
    filter.setValue("Q", forKey: "inputCorrectionLevel") // Q for medium quality

    guard let outputImage = filter.outputImage else { return nil }

    // Scale the QR code image so it looks clear on screen
    let transform = CGAffineTransform(scaleX: 10, y: 10)
    let scaledImage = outputImage.transformed(by: transform)

    // Create a CIContext and generate a CGImage from the CIImage
    let context = CIContext()
    if let cgImage = context.createCGImage(scaledImage, from: scaledImage.extent) {
        return UIImage(cgImage: cgImage)
    } else {
        return nil
    }
}

Inside ActivityReportExtension sandbox:

struct LineChartView: View {
    var body: some View {
        VStack {
            if let qrImage = generateQRCode2(from: "this is a test") {
                Image(uiImage: qrImage)
                    .resizable()
                    .scaledToFit()
                    .frame(width: 200, height: 200)
            } else {
                Text("QR Code generation failed")
            }
        }
    }
}

Case-ID: 12079215

Sorry some updates: I can render simple image in the extension:

Image(systemName: "photo")
                .resizable()
                .scaledToFit()
                .frame(width: 200, height: 200)
                .foregroundColor(.blue)

but still failed to render a QR Code.

Can CoreImage be used in the ActivityReportExtension?

I have conducted a lot of experiments and found that the problem is

let context = CIContext()

The function failed to run until this line in ActivityReportExtension.

Is Image rendering allowed inside ActivityReportExtension
 
 
Q