DeviceActivityMonitor startMonitoring error

I created my Device Activity Monitor extension, and then attempted to start monitoring using the code example from the video:

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)
}

The startMonitoring call always fails for me with the same error:

[monitor] Failed to create UsageTrackingAgent proxy: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.UsageTrackingAgent was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.UsageTrackingAgent was invalidated.}

Setting up the extension is a very manual process, so I likely missed a step somewhere, but any ideas on what this error might be indicating?

Replies

It looks like it's an issue with the extension not activating. I removed the extension target, which also removed the embedded .appex from my main app target, and I get the exact same result. It seems like it can't find the extension.

How did you create the Device Activity Monitor extension? There is no such extension type in Xcode 13 beta 3.

Add a Comment