Skip to content

Commit 897b29e

Browse files
authored
fix(google-sign-in): dispatch sign-in UI presentation to main thread (#808)
* fix(google-sign-in): dispatch sign-in UI presentation to main thread * fix(google-sign-in): move view controller access to main thread
1 parent f31d89f commit 897b29e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

.changeset/forty-mangos-feel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capawesome/capacitor-google-sign-in': patch
3+
---
4+
5+
fix(ios): dispatch sign-in UI presentation to main thread

packages/google-sign-in/ios/Plugin/GoogleSignIn.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ import GoogleSignIn
2222
}
2323

2424
@objc public func signIn(completion: @escaping (_ result: SignInResult?, _ error: Error?) -> Void) {
25-
guard let viewController = plugin.bridge?.viewController else {
26-
completion(nil, CustomError.viewControllerUnavailable)
27-
return
28-
}
29-
3025
let signInCompletion: (GIDSignInResult?, Error?) -> Void = { result, error in
3126
if let error = error {
3227
if (error as NSError).code == GIDSignInError.canceled.rawValue {
@@ -76,10 +71,16 @@ import GoogleSignIn
7671
completion(signInResult, nil)
7772
}
7873

79-
if let scopes = self.scopes, !scopes.isEmpty {
80-
GIDSignIn.sharedInstance.signIn(withPresenting: viewController, hint: nil, additionalScopes: scopes, completion: signInCompletion)
81-
} else {
82-
GIDSignIn.sharedInstance.signIn(withPresenting: viewController, completion: signInCompletion)
74+
DispatchQueue.main.async {
75+
guard let viewController = self.plugin.bridge?.viewController else {
76+
completion(nil, CustomError.viewControllerUnavailable)
77+
return
78+
}
79+
if let scopes = self.scopes, !scopes.isEmpty {
80+
GIDSignIn.sharedInstance.signIn(withPresenting: viewController, hint: nil, additionalScopes: scopes, completion: signInCompletion)
81+
} else {
82+
GIDSignIn.sharedInstance.signIn(withPresenting: viewController, completion: signInCompletion)
83+
}
8384
}
8485
}
8586

0 commit comments

Comments
 (0)