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

Answered by AsifmDev in 685516022

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>
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>
Designate principal class
 
 
Q