Device Activity Extension not being called

Hi all,

I am facing a problem following the code in the "Meet the Screen Time API" video. I've tried scheduling the monitoring time from 00:00 to 25:59 or some other time but functions in DeviceActivityMonitor are never being called.

I tried to print log from those functions, nothing shown. Is there any settings I've missed? In addition, I already changed the NSExtensionPrincipalClass value to my class name.

Any help would be appreciated!

Answered by g0mi in 713228022

I finally figured it out. The apps being monitored were not changing with my model selection. I had to call center.startMonitoring() after performing the selection. Also, I couldn't print logs from the extension. However, I could perform other actions like showing a notification to verify it worked.

Update with code.

I have added the following code extension DeviceActivityName{   static let daily = Self("daily") }

Run the following line after authorization `let schedule = DeviceActivitySchedule(     intervalStart: DateComponents(hour: 0, minute: 0),     intervalEnd: DateComponents(hour: 23, minute: 59),     repeats: true   )   let center = DeviceActivityCenter()

do{       try center.startMonitoring(.daily, during: schedule)     } catch {       print("error: (error)") }`

And In My Class overriding DeviceActivityMonitor: override func intervalDidStart(for activity: DeviceActivityName) {     super.intervalDidStart(for: activity)     let applicationTokens = model.selectionToDiscourage.applicationTokens     let categoryTokens = model.selectionToDiscourage.categoryTokens     model.store.shield.applications = applicationTokens.isEmpty ? nil : applicationTokens     model.store.shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.specific(categoryTokens)   }

where model is my model class for storing the selections

Accepted Answer

I finally figured it out. The apps being monitored were not changing with my model selection. I had to call center.startMonitoring() after performing the selection. Also, I couldn't print logs from the extension. However, I could perform other actions like showing a notification to verify it worked.

Device Activity Extension not being called
 
 
Q