์ค๋์ ์ฑ์ ์คํํ์ ๋ Screen Time API ๊ถํ ์ํ์ ๋ฐ๋ผ ์ด๊ธฐ ํ๋ฉด์ ๋์ ์ผ๋ก ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๊ตฌํํด์ผ ํ์ต๋๋ค. SceneDelegate๋ฅผ ํ์ฉํด ๊ถํ ์ํ๋ฅผ ํ์ธํ๊ณ , ์ ์ ํ ํ๋ฉด์ผ๋ก ์ ํํ๋ ๋ก์ง์ ๊ตฌํํ์ต๋๋ค.
AuthorizationCenter
๋ฅผ ์ฌ์ฉํ ๊ถํ ์ฒดํฌ๋จผ์ , ๊ถํ ์ํ๋ฅผ ํ์ธํ๊ธฐ ์ํด AuthorizationCenter.shared.authorizationStatus
๋ฅผ ํ์ฉํ์ด์. ์๋๋ ๊ถํ ์ํ๋ฅผ ํ์ธํ๋ ์ฝ๋์
๋๋ค.
import DeviceActivity
guard let authorizationStatus = AuthorizationCenter.shared.authorizationStatus else {
fatalError("Authorization status could not be retrieved.")
}
AuthorizationStatus
๋ฅผ ํตํด ์ฌ์ฉ์๊ฐ ๊ถํ์ ์น์ธํ๋์ง ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์์ด์.SceneDelegate
์์ SceneDelegate
์์ ๊ถํ ์ํ์ ๋ฐ๋ผ ์ด๊ธฐ ํ๋ฉด์ ์ค์ ํ๋ ๋ก์ง์ ์ถ๊ฐํ์ต๋๋ค.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: scene)
let rootViewController: UIViewController
// FamilyControls์ ๊ถํ ์ํ ํ์ธ
let authorizationsStatus = AuthorizationCenter.shared.authorizationStatus
if authorizationsStatus == .approved {
// ๊ถํ์ด ์น์ธ๋ ์ํ -> StarListViewController๋ก ์คํ
rootViewController = StarListViewController()
} else {
// ๊ถํ ๋ฏธ์น์ธ ์ํ -> PermissionViewController๋ก ์คํ
rootViewController = PermissionViewController()
}
let navigationController = UINavigationController(rootViewController: rootViewController)
window.rootViewController = navigationController
window.makeKeyAndVisible()
self.window = window
}
AuthorizationCenter.shared.authorizationStatus
๋ก ๊ถํ ์ํ๋ฅผ ํ์ธ.approved
์ํ์ผ ๊ฒฝ์ฐ StarListViewController
๋ฅผ ์ด๊ธฐ ํ๋ฉด์ผ๋ก ์ค์ PermissionViewController
๋ก ์ด๋์ด๋ฒ ์์
์ ํตํด Screen Time API ๊ถํ ์ค์ ํ๋ฆ์ ๋ช
ํํ ์ดํดํ ์ ์์์ต๋๋ค. ํนํ, ์ฑ์ ์ด๊ธฐ ํ๋ฉด์ ๋์ ์ผ๋ก ์ค์ ํ๋ ๊ณผ์ ์์ SceneDelegate
๋ฅผ ํ์ฉํด ๋ก์ง์ ๊น๋ํ๊ฒ ๋ถ๋ฆฌํ ์ ์์์ต๋๋ค.
๋ค์ ๊ธ์์๋ PermissionViewController์์ ์ฌ์ฉ์๊ฐ ๊ถํ์ ์น์ธํ๋ ๋ฒํผ์ ๋๋ ์ ๋ ๊ถํ ์์ฒญ ๋ก์ง์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ๋ค๋ค๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค!