Skip to content

Instantly share code, notes, and snippets.

@rslifka
Last active October 23, 2021 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rslifka/3caefdbaad6c1306d9d52886bdbbad1a to your computer and use it in GitHub Desktop.
Save rslifka/3caefdbaad6c1306d9d52886bdbbad1a to your computer and use it in GitHub Desktop.
Obtaining a reference to an ASPresentationAnchor for use with ASWebAuthenticationSession in SwiftUI
private var window: UIWindow {
guard
let scene = UIApplication.shared.connectedScenes.first,
let windowSceneDelegate = scene.delegate as? UIWindowSceneDelegate,
let window = windowSceneDelegate.window as? UIWindow
else {
return UIWindow()
}
return window
}
@rslifka
Copy link
Author

rslifka commented Oct 23, 2021

The source for this is Kilo Loco's AWS Amplify Auth Web UI for iOS | SwiftUI 2.0, Xcode 12 video. It's the only place I've been able to discover how ASPresentationAnchor might be obtainable in SwiftUI.

I'm a complete Xcode/Swift/SwiftUI/iOS novice so I have no idea if there's a different/better/easier way to do this. Please comment if so :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment