Designate principal class

Hello, I am wondering how to designate my DeviceActivityMonitor extension as the principal class on Xcode 13 beta 5

Documentation: https://developer.apple.com/documentation/deviceactivity/deviceactivitymonitor

Accepted Answer

Use "Call directory Extension" Template and create an extension. than create a sub class of "DeviceActivityMonitor" and change that class as a principle class in the info.plist



//  MyDeviceActivityMonitor




import Foundation

import DeviceActivity

import ManagedSettings



class MyDeviceActivityMonitor: DeviceActivityMonitor{

    

    override func intervalDidStart(for activity: DeviceActivityName) {

        super.intervalDidStart(for: activity)

    }

    

    override func intervalDidEnd(for activity: DeviceActivityName) {

        super.intervalDidEnd(for: activity)

    }

    

    override func eventDidReachThreshold(_ event:DeviceActivityEvent.Name,activity:DeviceActivityName){

        

        super.eventDidReachThreshold(event, activity: activity)

    }

    

}




<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

	<key>NSExtension</key>

	<dict>

		<key>NSExtensionPointIdentifier</key>

		<string>com.apple.deviceactivity.monitor-extension</string>

		<key>NSExtensionPrincipalClass</key>

		<string>$(PRODUCT_MODULE_NAME).MyDeviceActivityMonitor</string>

	</dict>

</dict>

</plist>
  • did all of the above and still none of the methods on MyDeviceActivityMonitor gets called. i'm using the monitor.startMonitoring() method and nothing appends

  • @vova085 Did you add Family Controls capability to your extension? If not please add it and do the following,

    Steps to debug extension via Xcode, 

    Run the app on device via Xcode 2. Go to menu Debug -> Attach to Process -> Search for the extension name you have given for 'com.apple.deviceactivity.monitor-extension' and attach it Now you have two process attached for debug. 

    Steps to collect logs from console, 

    Launch Console and start monitor device traffic 2. Search for your extension name given for 'com.apple.deviceactivity.monitor-extension' under category 'Process'
Add a Comment

Answers

Use "Call directory Extension" Template and create an extension. than create a sub class of "DeviceActivityMonitor" and change that class as a principle class in the info.plist



//  MyDeviceActivityMonitor




import Foundation

import DeviceActivity

import ManagedSettings



class MyDeviceActivityMonitor: DeviceActivityMonitor{

    

    override func intervalDidStart(for activity: DeviceActivityName) {

        super.intervalDidStart(for: activity)

    }

    

    override func intervalDidEnd(for activity: DeviceActivityName) {

        super.intervalDidEnd(for: activity)

    }

    

    override func eventDidReachThreshold(_ event:DeviceActivityEvent.Name,activity:DeviceActivityName){

        

        super.eventDidReachThreshold(event, activity: activity)

    }

    

}




<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

	<key>NSExtension</key>

	<dict>

		<key>NSExtensionPointIdentifier</key>

		<string>com.apple.deviceactivity.monitor-extension</string>

		<key>NSExtensionPrincipalClass</key>

		<string>$(PRODUCT_MODULE_NAME).MyDeviceActivityMonitor</string>

	</dict>

</dict>

</plist>
  • did all of the above and still none of the methods on MyDeviceActivityMonitor gets called. i'm using the monitor.startMonitoring() method and nothing appends

  • @vova085 Did you add Family Controls capability to your extension? If not please add it and do the following,

    Steps to debug extension via Xcode, 

    Run the app on device via Xcode 2. Go to menu Debug -> Attach to Process -> Search for the extension name you have given for 'com.apple.deviceactivity.monitor-extension' and attach it Now you have two process attached for debug. 

    Steps to collect logs from console, 

    Launch Console and start monitor device traffic 2. Search for your extension name given for 'com.apple.deviceactivity.monitor-extension' under category 'Process'
Add a Comment