ShieldActionExtention not calling code or printing to console

I'm using ShieldActionExtention to make a HTTP request to a server when a user selects one of the buttons on their app shield. The apps are shielded, but nothing happens when I press one of the shield buttons. There is no message on the server signaling an HTTP request and nothing is printed to the XCode console while in debug mode.

Here is my code for my Shield Action Extention

//  ShieldActionExtension.swift
//  ShieldAction
//
//
import Foundation
import UIKit
import SwiftUI
import ManagedSettings

// Override the functions below to customize the shield actions used in various situations.
// The system provides a default response for any functions that your subclass doesn't override.
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
class ShieldActionExtension: ShieldActionDelegate {
    override func handle(action: ShieldAction, for application: ApplicationToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
        print(action)
        let deviceID = UserDefaults.standard.string(forKey: UserDefaultKeys.userID.rawValue)!
        Task{
            do{
                print("sending to server")
                try await PlayerLosesGame(playerID: deviceID)
                completionHandler(.close)

            } catch {
                print("error occured on the shield")
                completionHandler(.none)
            }
        }
    }
    
    override func handle(action: ShieldAction, for webDomain: WebDomainToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
        print(action)
        let deviceID = UserDefaults.standard.string(forKey: UserDefaultKeys.userID.rawValue)!
        Task{
            do{
                print("sending to server")
                try await PlayerLosesGame(playerID: deviceID)
                completionHandler(.close)

            } catch {
                print("error occured on the shield")
                completionHandler(.none)
            }
        }
    }
    
    override func handle(action: ShieldAction, for category: ActivityCategoryToken, completionHandler: @escaping (ShieldActionResponse) -> Void) {
        print(action)
        let deviceID = UserDefaults.standard.string(forKey: UserDefaultKeys.userID.rawValue)!
        Task{
            do{
                print("sending to server")
                try await PlayerLosesGame(playerID: deviceID)
                completionHandler(.close)

            } catch {
                print("error occured on the shield")
                completionHandler(.none)
            }
        }
        //completionHandler(.close)
    }
    
    func PlayerLosesGame(playerID: String) async throws{
        let url = URL(string: ServerConnection.GetWebsite() + "game/find?playerID="+playerID)!
        
        var request = URLRequest(url: url)

        request.httpMethod = "GET"
        
        print("trying this out")

        let (data, _) = try await URLSession.shared.data(for: request)
        
    }
    
}

I believe all my targets are set up correctly and should be working. Why is nothing happening?

I’m not an expert on the Screen Time APIs but I wanted to comment on this:

nothing is printed to the XCode console

When you have code running in weird contexts, like an app extension, it’s best not to relying on print(…). Rather, use the system log for your logging. See Your Friend the System Log for the details.

If you convert these print(…) calls to log points, what do you see?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

For privacy reasons you cannot make API calls from your Shield Extension. For parental controls app you you will need to do this outside of the extension's runtime.

ShieldActionExtention not calling code or printing to console
 
 
Q