shielding and blocking apps

i'm trying to shield and block apps on child device.

i managed to block apps by creating a  variable blockedApps : Set = Set() that contains a list of applications like Application(bundleIdentifier: "com.apple.calculator") inside the intervalDidStart on my DeviceActivityMonitor extension

now i'm trying to shield an app using the same extension and nothing happens. for this i used this code inside intervalDidStart:

  let calculatorApp = Application(bundleIdentifier: "com.apple.calculator")     var blockedApps : Set = Set()           guard let token = calculatorApp.token else {       return     }     blockedApps = [token]     store.shield.applications = blockedApps

and i cant tell what is the reason for this not working

  1. is there a token issue that is nil?
  2. does shielding requires a different app extension?
  3. does my app extension requires some additional configuration maybe a different NSExtensionPointIdentifier?

Accepted Reply

played with this some more and answered my own questions:

  1. the token is unavailable/nil
  2. i managed to shield an app with the same extension used for blocking
  3. no my app extension does not require some additional configuration
  • Do you mind sharing the stuff how did you mange to share app tokens to extension. Which you then used to sheild the apps?

  • I used User Defaults.

  • How did you manage to store this into UserDefaults? Application, Category or WebDomain are not encodable.

Add a Comment

Replies

played with this some more and answered my own questions:

  1. the token is unavailable/nil
  2. i managed to shield an app with the same extension used for blocking
  3. no my app extension does not require some additional configuration
  • Do you mind sharing the stuff how did you mange to share app tokens to extension. Which you then used to sheild the apps?

  • I used User Defaults.

  • How did you manage to store this into UserDefaults? Application, Category or WebDomain are not encodable.

Add a Comment

Hi,

I am not able to call DeviceActivity callback methods to block apps, could you please share your code for Device Activity Extension or steps to create Device Activity extension.

  • create a new extension (i chose call directory extension but maybe at the time you read this there will be an extension for activity monitor)int the info pList of the extension set the NSExtensionPointIdentifier key to be com.apple.deviceactivity.monitor-extensiongo to the swift file that was created (will be called CallDirectoryHandler if you chose a call directory extension ) and make it implement the

    DeviceActivityMonitor protocol

    you can change the name of this class if you wantset the NSExtensionPrincipalClass inside the pList to the name of the class that implementing DeviceActivityMonitor protocoladd the override methods you want (the most relevant ones are: intervalDidEnd and intervalDidStart. see example at the end of the message)call the DeviceActivityCenter start monitor on you APP Not the Extension with the needed parameter (you can see that on the tutorial of this api)

    example overridden methods:

       override func intervalDidStart(for activity: DeviceActivityName) {       super.intervalDidStart(for: activity)   }       override func intervalDidEnd(for activity: DeviceActivityName) {

        super.intervalDidEnd(for: activity)   }

Add a Comment