Post

Replies

Boosts

Views

Activity

Reply to About the problem that DeviceActivityMonitorExtension does not work
On February 9, I encountered the situation where the monitoring process was killed again. The monitoring processes of my two different applications were all killed, and I don’t know why. The only difference is that on February 8, I updated the system. However, on February 8, the monitoring still existed. In order to reduce memory, I used static methods in monitoring. And they were all looped at 0:00.
Topic: App & System Services SubTopic: General Tags:
Feb ’25
Reply to About the problem that DeviceActivityMonitorExtension does not work
After it expired on February 9, it also expired on February 14. The failure codes are as follows: let deviceActivityCenter = DeviceActivityCenter() let deviceActivityName = DeviceActivityName( "GoalHabit-" + habit.id.uuidString ) let startInterval = DateComponents(hour : 0, minute : 0) let endInterval = DateComponents(hour : 23, minute : 59) let schedule = DeviceActivitySchedule( intervalStart: startInterval, intervalEnd: endInterval, repeats: true ) do{ try deviceActivityCenter.startMonitoring( deviceActivityName, during: schedule, events: [deviceActivityEventName : deviceActivityEvent] ) return true }catch { return false } deviceActivityEvent is an action to be performed after reaching the threshold override func eventDidReachThreshold(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) { super.eventDidReachThreshold(event, activity: activity) let viewContext = PersistenceController.shared.container.viewContext let (year, month, day) = getYearMonthDay(.now) let newHabitRecord = HabitRecord(context: viewContext) newHabitRecord.id = UUID() newHabitRecord.habitId = id newHabitRecord.year = Int16(year) newHabitRecord.month = Int16(month) newHabitRecord.day = Int16(day) newHabitRecord.duration = middleValue * 60 // 当前思考的秒 newHabitRecord.type = 0 newHabitRecord.createDate = .now do { try viewContext.save() WidgetCenter.shared.reloadAllTimelines() }catch { } } I wish I knew why it failed。 My system has been upgraded to 18.3。
Topic: App & System Services SubTopic: General Tags:
Feb ’25
Reply to Summary of issues encountered with the Screen Time interface
private func buildEvents(with tokens: Set<ApplicationToken>, prefix: String) -> [DeviceActivityEvent.Name: DeviceActivityEvent] { var events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [:] for index in 0..<30 { // Set time threshold: first 29 events every 2 minutes, last event in 1 hour let threshold = (index == 29) ? DateComponents(hour: 1) : DateComponents(minute: (index + 1) * 2) let name = DeviceActivityEvent.Name("\(prefix)|\(index)") if #available(iOS 17.4, *) { events[name] = DeviceActivityEvent( applications: tokens, threshold: threshold, includesPastActivity: false ) }else { events[name] = DeviceActivityEvent( applications: tokens, threshold: threshold ) } } return events } This is my DeviceActivityEvent generation code. I hope the app is used to remind me every two minutes.
Topic: Community SubTopic: Apple Developers Tags:
Jun ’25