ShieldConfigurationExtension 사용하기
ShieldConfigurationExtension을 활용해 ShieldView의 스타일을 커스텀할 수 있다.
AppGroups로 공유하고 있는 UserDefaults 데이터를 가져와 활용할수 있다.
import ManagedSettings
import ManagedSettingsUI
import UIKit
class ShieldConfigurationExtension: ShieldConfigurationDataSource {
let imageName = "stopwatch"
override func configuration(shielding application: Application) -> ShieldConfiguration {
// Customize the shield as needed for applications.
return ShieldConfiguration(
backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial,
backgroundColor: UIColor.white,
icon: UIImage(systemName: imageName),
title: ShieldConfiguration.Label(text: "No app for you", color: .yellow),
subtitle: ShieldConfiguration.Label(text: "Sorry, no apps for you", color: .black),
primaryButtonLabel: ShieldConfiguration.Label(text: "Ask for a break?", color: .black),
secondaryButtonLabel: ShieldConfiguration.Label(text: "Quick Quick", color: .black)
)
}
override func configuration(shielding application: Application, in category: ActivityCategory) -> ShieldConfiguration {
// Customize the shield as needed for applications shielded because of their category.
return ShieldConfiguration(
backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial,
backgroundColor: UIColor.white,
icon: UIImage(systemName: imageName),
title: ShieldConfiguration.Label(text: "No app for you", color: .yellow),
subtitle: ShieldConfiguration.Label(text: "Sorry, no apps for you", color: .black),
primaryButtonLabel: ShieldConfiguration.Label(text: "Ask for a break?", color: .black),
secondaryButtonLabel: ShieldConfiguration.Label(text: "Quick Quick", color: .black)
)
}
// WebDomainToken으로 제한한 앱의 ShieldView Custom
override func configuration(shielding webDomain: WebDomain) -> ShieldConfiguration {
// Customize the shield as needed for web domains.
ShieldConfiguration()
}
override func configuration(shielding webDomain: WebDomain, in category: ActivityCategory) -> ShieldConfiguration {
// Customize the shield as needed for web domains shielded because of their category.
ShieldConfiguration()
}
}
NOTICE
- AppGroups로 공유하고 있는 UserDefaults 데이터를 가져와 활용할수 있다.
- 커스텀은 스타일만 가능하며, State 변경은 불가능하다.
- Category로 제한한 앱과 Application으로 제한한 앱이 보여지는 뷰가 다르다.
- Category에 포함된 앱이 하나일 경우 Application으로 인식하지 않고 Category로 인식한다.
Link