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
Can I create Image inside the ActivityReportExtension? I cannot even render a simple image (not QR code) inside the extension.
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")
}
}
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Questions
I am developing a social screen time application that enables users to create “sprints” and set sprint goals—essentially time limits on usage for selected applications. For this functionality, users select the apps they wish to manage using the FamilyActivitySelection interface (from the FamilyControls framework).
However, our backend needs to distinguish each application uniquely (for example, via the app’s bundle identifier) in order to correctly map and enforce user-defined sprint goals. Unfortunately, we are encountering an issue where retrieving the bundle identifier directly from the FamilyActivitySelection is returning nil. As a result, we are unable to globally identify the selected apps.
Could you please advise if there is an alternative method or property available in the FamilyControls API that would allow us to uniquely identify the apps? Alternatively, is there another approach recommended by Apple for obtaining a global identifier for applications selected via FamilyActivitySelection?
Thank you for your time and assistance. I look forward to your guidance on how to resolve this issue.
Code
The following is the print statement I used to check if bundleIdentifier is nil after I stored user's selections to the variable selection using familyActivityPicker:
for app in selection!.applications {
let bundleId = app.bundleIdentifier ?? "Unknown Bundle ID"
let token = app.token
let localizedDisplayName = app.localizedDisplayName ?? "Unknown Localized Display Name"
print("Selected app bundle identifier: \(bundleId)")
print("localizedDisplayName: \(localizedDisplayName)")
}
Console log result I received from the print statement above:
Selected app bundle identifier: Unknown Bundle ID
localizedDisplayName: Unknown Localized Display Name
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Family Controls
Managed Settings
Screen Time