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?