I am developing a parental control app using Flutter and platform channels to integrate with the Screen Time API on iOS. The app has two interfaces - one for the parent and one for the child. I have set up Family Sharing correctly and installed the app on both the parent's and child's devices. However, I am encountering some issues with the Family Activity Selection feature.
It's worth noting that I am a Flutter developer with limited knowledge of Swift and iOS development, so if my issues stem from a mistake I made, please forgive me.
The problems I am facing are as follows:
-
When calling the family activity selection, the list of apps shown in the apps sheet is from the parent's device, and no apps from the child's device are displayed. I have double-checked that Family Sharing and other necessary configurations are set up correctly, including the family control capability.
-
Even if I select apps on the parent's device, the selected apps are not returned in the result. The returned array is empty. Additionally, there is no close or done button on the sheet, and drag-to-dismiss is not working either. This might be an issue with the way I have written the code (most of the native code was generated by AI assistants like Claude and GPT, as I am a Flutter developer with limited knowledge of Swift and iOS development).
-
I have tested other parental control apps that use the Screen Time API and observed the same issue, where the parent's apps are shown on the parent's device instead of the child's apps.
For more context, I have provided the relevant code snippet below:
import Flutter
import FamilyControls
import ManagedSettings
import SwiftUI
class FamilyActivityHandler: NSObject, FlutterPlugin {
// ...
private func openFamilyActivityPicker(result: @escaping FlutterResult) {
let store = ManagedSettingsStore()
let selection = FamilyActivitySelection()
// Adjusting for UIWindowScene for iOS 15 and later
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
result(FlutterError(code: "NO_WINDOW_SCENE", message: "No window scene found", details: nil))
return
}
let viewController = UIHostingController(rootView: FamilyActivityPicker(selection: .constant(selection)))
viewController.modalPresentationStyle = .formSheet
window.rootViewController?.present(viewController, animated: true, completion: nil)
DispatchQueue.main.async {
let applications = selection.applicationTokens
let categories = selection.categoryTokens
let webDomains = selection.webDomainTokens
store.shield.applications = applications.isEmpty ? nil : applications
store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categories, except: Set())
store.shield.webDomains = webDomains
// Custom method to generate descriptive strings for tokens
let applicationsDescription = applications.map { token in
// Implement a custom description method or use an identifier property
"\(token)"
}
let categoriesDescription = categories.map { token in
// Implement a custom description method or use an identifier property
"\(token)"
}
let webDomainsDescription = webDomains.map { token in
// Implement a custom description method or use an identifier property
"\(token)"
}
let resultDict: [String: Any] = [
"applications": applicationsDescription,
"categories": categoriesDescription,
"webDomains": webDomainsDescription
]
result(resultDict)
}
}
}
I would greatly appreciate any guidance or insights from the community on how to resolve these issues and properly implement the Family Activity Selection feature using the Screen Time API in a Flutter app with platform channels.
Thank you in advance for your help!