Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let userID = UserDefaults.standard.object(forKey: "userId") as? String {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: userID) { (state, error) in
DispatchQueue.main.async {
switch state
{
case .authorized: // valid user id
self.settings.authorization = 1
break
case .revoked: // user revoked authorization
self.settings.authorization = -1
break
case .notFound: //not found
self.settings.authorization = 0
break
default:
break
}
}
}
}
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView.environmentObject(settings))
self.window = window
window.makeKeyAndVisible()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment