Hi all,
I’m trying to work with the Shield Configuration Extension, and I’m running into some problems that I’m unsure are solvable.
See below for my code. I’m trying to create a second button that allows you to go to a web domain or another app. As I see it this is not possible following the Apple documentation regarding the Shield Config. But is there perhaps a work around?
import ManagedSettings
import ManagedSettingsUI
import UIKit
class ShieldConfigurationExtension: ShieldConfigurationDataSource {
// Default shield configuration for any application
override func configuration(shielding application: Application) -> ShieldConfiguration {
return ShieldConfiguration(
backgroundBlurStyle: .dark,
backgroundColor: SharedAssets.uistepperBGPurple2.withAlphaComponent(0.9),
icon: UIImage(named: "squaredIconSmallNoBG"),
title: .init(text: "Blocked By App", color: SharedAssets.uistepperWhite),
subtitle: .init(text: subtitleText(for: application), color: UIColor.secondaryLabel),
primaryButtonLabel: .init(text: "OK", color: SharedAssets.uistepperWhite),
primaryButtonBackgroundColor: SharedAssets.uistepperBGPurple2,
secondaryButtonLabel: secondaryButtonLabel(for: application)
)
}
// Shield configuration for applications shielded because of their category
override func configuration(shielding application: Application, in category: ActivityCategory) -> ShieldConfiguration {
return ShieldConfiguration(
backgroundBlurStyle: .dark,
backgroundColor: UIColor.black.withAlphaComponent(0.7), // Darker background for this category
icon: UIImage(named: "categoryIcon"),
title: .init(text: "Blocked by App - Category", color: UIColor.white),
subtitle: .init(text: "This app is blocked due to your activity category.", color: UIColor.lightGray),
primaryButtonLabel: .init(text: "OK", color: UIColor.white),
primaryButtonBackgroundColor: UIColor.black,
secondaryButtonLabel: nil // No secondary button for this category
)
}
// Shield configuration for web domains
override func configuration(shielding webDomain: WebDomain) -> ShieldConfiguration {
return ShieldConfiguration(
backgroundBlurStyle: .dark,
backgroundColor: UIColor.darkGray.withAlphaComponent(0.8),
icon: UIImage(named: "webIcon"),
title: .init(text: "Blocked Web Domain", color: UIColor.white),
subtitle: .init(text: "You can't access this web domain right now.", color: UIColor.gray),
primaryButtonLabel: .init(text: "Close", color: UIColor.white),
primaryButtonBackgroundColor: UIColor.darkGray,
secondaryButtonLabel: nil // No secondary button for web domains
)
}
// Shield configuration for web domains shielded because of their category
override func configuration(shielding webDomain: WebDomain, in category: ActivityCategory) -> ShieldConfiguration {
return ShieldConfiguration(
backgroundBlurStyle: .dark,
backgroundColor: UIColor.brown.withAlphaComponent(0.7),
icon: UIImage(named: "categoryWebIcon"),
title: .init(text: "Blocked Web Domain - Category", color: UIColor.white),
subtitle: .init(text: "This web domain is blocked due to your activity category.", color: UIColor.lightGray),
primaryButtonLabel: .init(text: "OK", color: UIColor.white),
primaryButtonBackgroundColor: UIColor.brown,
secondaryButtonLabel: nil // No secondary button for this category
)
}
// Function to generate the subtitle text for an application
private func subtitleText(for application: Application) -> String {
// An inspirational quote as the subtitle text
return "Discipline is the bridge between goals and accomplishment."
}
// Function to determine the secondary button label for an application
private func secondaryButtonLabel(for application: Application) -> ShieldConfiguration.Label? {
// Customize the secondary button label
return .init(text: "Get some motivation", color: UIColor.lightGray)
}
}