Skip to content

Commit 49d4c0a

Browse files
committed
Let the system manage login sheet presentation
1 parent 7e582a0 commit 49d4c0a

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import Foundation
22
import AuthenticationServices
33

4-
final class WebAuthenticationPresentationAnchorProvider: NSObject, ASWebAuthenticationPresentationContextProviding {
5-
let anchor: ASPresentationAnchor
4+
final class WebAuthenticationPresentationContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {
65

7-
init(anchor: ASPresentationAnchor) {
8-
self.anchor = anchor
6+
override init() {
7+
super.init()
98
}
109

1110
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
12-
anchor
11+
ASPresentationAnchor() // Let the system manage the presentation
1312
}
1413
}

WordPress/Classes/Login/WordPressDotComAuthenticator.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import Alamofire
99
///
1010
/// API doc: https://developer.wordpress.com/docs/oauth2/
1111
struct WordPressDotComAuthenticator {
12+
13+
private let contextProvider = WebAuthenticationPresentationContextProvider()
14+
1215
enum Error: Swift.Error {
1316
case invalidCallbackURL
1417
case loginDenied(message: String)
@@ -103,7 +106,6 @@ struct WordPressDotComAuthenticator {
103106

104107
let callbackURL: URL = try await withCheckedThrowingContinuation { continuation in
105108
DispatchQueue.main.async {
106-
let provider = WebAuthenticationPresentationAnchorProvider(anchor: viewController.view.window ?? UIWindow())
107109
let session = ASWebAuthenticationSession(url: authorizeURL, callbackURLScheme: "x-wordpress-app") { url, error in
108110
if let url {
109111
continuation.resume(returning: url)
@@ -112,7 +114,8 @@ struct WordPressDotComAuthenticator {
112114
continuation.resume(throwing: Error.cancelled)
113115
}
114116
}
115-
session.presentationContextProvider = provider
117+
118+
session.presentationContextProvider = contextProvider
116119
session.start()
117120
}
118121
}

WordPress/Classes/Networking/LoginClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final actor LoginClient {
5858
site: site,
5959
appName: appNameValue,
6060
appId: appId,
61-
contextProvider: WebAuthenticationPresentationAnchorProvider(anchor: anchor ?? ASPresentationAnchor())
61+
contextProvider: WebAuthenticationPresentationContextProvider()
6262
)
6363

6464
let returnValue: Result<WordPressOrgCredentials, LoginClientError>

0 commit comments

Comments
 (0)