I have faced a problem with Screen Time API in iOS. I have successfully authorised using AuthorizationCenter.shared.requestAuthorization
, I have checked status using AuthorizationCenter.shared.authorizationStatus
, but the problem is with DeviceActivityCenter
.
In my ViewModel I have a function, that I'm calling after checking Authorisation Status:
func startMonitoringAccordingSchedule() {
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)
print(" Success with Starting Monitor Activity")
} catch {
print(" Error with Starting Monitor Activity: \(error.localizedDescription)")
}
}
The problem is that with Succeed Authorisation, with Status = Approved, this function doesn't work, try center.startMonitoring(.daily, during: schedule)
fails and it goes to the catch block.
Can anybody help me with that?