Post

Replies

Boosts

Views

Activity

Summary of issues encountered with the Screen Time interface
I have developed three apps using the Screen Time API. The following are common problems I encountered in the three apps: DeviceActivityMonitorExtension is automatically killed after running for a few days (frequently) The same DeviceActivityEvent in DeviceActivityMonitorExtension is triggered twice during eventDidReachThreshold (especially obvious in iOS18.5) Screen Time authorization is automatically canceled for no reason (occasionally) I hope to get help
4
1
97
2w
DeviceActivityEvent will still execute even if the app is not in use
I use DeviceActivityCenter to monitor app usage. For DeviceActivityEvent, I set 30 events, and the threshold of each event increases by 2 minutes: var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [:] for index in 0..<30 { let threshold = (index == 29) ? DateComponents(hour: 1) : DateComponents(minute: (index + 1) * 2) let name = DeviceActivityEvent.Name("\(prefix)|\(index)") events[name] = DeviceActivityEvent(applications: tokens, threshold: threshold) } After reaching the last DeviceActivityEvent, I will restart directly in DeviceActivityMonitor private func restartMonitoring(activity: DeviceActivityName) { let center = DeviceActivityCenter() let currentEvents = center.events(for: activity) do { try center.startMonitoring(activity, during: schedule, events: currentEvents) } catch { print("Fail: \(error)") } } But I found that after restarting, DeviceActivityEvent will be automatically executed even if I don't use the app. My iOS version is 18.5
0
0
62
2w
FamilyActivityPicker will have a problem closing the parent element fullScreenCover in the 18.4 official version
.fullScreenCover(isPresented: $isShow) { Button(action : { isPresented.toggle() }){ Text("Choose") } .familyActivityPicker( isPresented: $isPresented, selection: $selection) .onChange(of: selection){ value in } } In the official version of iOS 18, when I click the Done button of familyActivityPicker, the fullScreenCover pop-up box will disappear.
2
2
99
Apr ’25
Color picker not working
HStack{ FormLable(text: NSLocalizedString("Color", comment: "")) Spacer() Image(systemName: "circle.fill") .font(.system(size: AppFontSize.baseSize.size() * 1.2, weight: .medium)) .foregroundColor(color) .overlay(ColorPicker("Color", selection: $color).labelsHidden().opacity(0.015)) } This is how I use the color picker. I used the same code in two different apps, and the color picker appeared in one app but not in the other. By the way, I upgraded Xcode to the latest version.
2
0
331
Feb ’25
About the problem that DeviceActivityMonitorExtension does not work
I am developing an app that can help users disable selected apps at a specified time, so that users can get away from their phones and enjoy real life. Here is my data structure: extension ActivityModel { @NSManaged public var id: UUID @NSManaged public var name: String @NSManaged public var weeks: Data @NSManaged public var weekDates: Data @NSManaged public var appTokens: Data } Among them, weeks is of [Bool] type, indicating which weeks from Sunday to Saturday are effective; weekDates is of [[Date,Date]] type, indicating the effective time period; appTokens is of Set type, indicating the selected apps。 At the beginning, I will open a main monitor: let deviceActivityCenter = DeviceActivityCenter() do{ try deviceActivityCenter.startMonitoring( DeviceActivityName(activityModel.id), during: DeviceActivitySchedule( intervalStart: DateComponents(hour: 0,minute: 0,second: 0), intervalEnd: DateComponents(hour: 23,minute: 59,second: 59), repeats: true ) ) }catch { return false } Since the time range may be different every day, I will start the sub-monitoring of the day every time the main monitoring starts: override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) if activity.rawValue.hasPrefix("Sub-") { ActivityModelManager.disableApps( Tools.getUUIDFromString(activity.rawValue) ) return } let weekIndex = Calendar.current.component(.weekday, from: .now) let weeks = ActivityModelManager.getWeeks(activity.rawValue) if weeks[weekIndex] { let weekDates = ActivityModelManager.getWeekDates(activity.rawValue) let deviceActivityCenter = DeviceActivityCenter() do{ try deviceActivityCenter.startMonitoring( DeviceActivityName("Sub-" + activityModel.id), during: DeviceActivitySchedule( intervalStart: getHourAndMinute(weekDates[weekIndex][0]), intervalEnd: getHourAndMinute(weekDates[weekIndex][1]), repeats: false ) ) }catch { return } }esle { return } } I will judge whether it is main monitoring or sub monitoring based on the different activity names. When the sub-monitor starts, I will get the bound application and then disable it: static func disableApps(_ id : UUID){ let appTokens = ActivityModelManager.getLimitAppById(id) let name = ManagedSettingsStore.Name(id.uuidString) let store = ManagedSettingsStore(named: name) store.shield.applications = appTokens return } When the child monitoring is finished, I resume the application: static func enableApps(_ id : UUID){ let name = ManagedSettingsStore.Name(id.uuidString) let store = ManagedSettingsStore(named: name) store.shield.applications = [] } The above is my code logic. When using DeviceActivityMonitorExtension, I found the following problems: intervalDidStart may be called multiple times, resulting in several sub-monitors being started. After a period of time, the monitoring is turned off. The static methods enableApps and disableApps are sometimes not called
4
0
522
Feb ’25
Issues with Multiple Activations and Interruption of intervalDidStart in DeviceActivity When Using ScreenTime API
I am a Swift developer using the ScreenTime API to develop an app that helps users manage app usage time on their phones. While working with DeviceActivity, I've noticed that it sometimes gets activated multiple times in succession, and occasionally, the code within intervalDidStart stops executing midway. What could be the cause of this?
0
0
282
Nov ’24
Bug in DeviceActivity
I am developing an app using DeviceActivity. let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour : 0, minute : 0, second: 1), intervalEnd: DateComponents(hour : 23, minute : 59, second: 59), repeats: true ) I found that on the second day, intervalDidStart(for: DeviceActivityName) gets called multiple times. I also tried let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour : 0, minute : 0, second: 1), intervalEnd: DateComponents(hour : 23, minute : 59, second: 59), repeats: false ) and started monitoring for the next day in the intervalDidEnd(for: DeviceActivityName) method. but , intervalDidStart(for: DeviceActivityName) still gets called multiple times. How should I resolve this issue?
0
0
419
Oct ’24
Issue with Missing Application Token Data in DeviceActivityEvent
I am developing an application for managing screen time, and I encountered an issue when retrieving DeviceActivityEvent bound to a specific DeviceActivityName using the events method of DeviceActivityCenter. I noticed that the application token data bound to DeviceActivityEvent is missing. Could you help me understand why this might be happening?
1
0
455
Jul ’24
Reducing Memory Usage in DeviceActivityMonitor: Help Needed
Hi everyone, I am a beginner in Swift and I am currently using DeviceActivityMonitor to develop an app for parents to control their children's app usage time. During the development process, I found that the DeviceActivityMonitor has a 6MB memory limit in the background, and my app exceeds this limit after running for a long time. I would like to know how to reduce the memory usage of DeviceActivityMonitor in the background, or where I can check the memory usage of DeviceActivityMonitor and see which variables are consuming memory. Additionally, I want to know if a new instance of the DeviceActivityMonitor class is created every time it is called? Thank you for your help!
1
2
601
Jul ’24