You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, my iOS app can't restorePreviousSignIn in v6.0.1.
Before, I used signIn:didSignInForUser:withError: to restore user signIn state, and it works fine.
Now, I follow your migration guide, to Move the logic from signIn:didSignInForUser:withError: to the callback block of signInWithConfiguration:presentingViewController:callback:.
Now, I put signInWithConfiguration:presentingViewController:callback: into Google signIn button, I could sign in but when I close and reopen my app, signInWithConfiguration:presentingViewController:callback: is not triggered, then I couldn't restore the previous user signIn state.
Is this the correct position it should be, how could I fix this issue? This version is quite new, I couldn't find related issue in internet, please help, guys.
@objc func signInButtonTapped(_ sender: Any) {
GIDSignIn.sharedInstance.signIn(with: modelController.signInConfig, presenting: self) { [weak self] user, error in
if let error = error {
print("SignIn failed, \(error), \(error.localizedDescription)")
} else {
print("Authenticate successfully")
let driveScope = "https://www.googleapis.com/auth/drive.readonly"
guard let user = user else { return }
let grantedScopes = user.grantedScopes
print("scopes: \(String(describing: grantedScopes))")
if grantedScopes == nil || !grantedScopes!.contains(driveScope) {
// Request additional Drive scope if it doesn't exist in scope.
GIDSignIn.sharedInstance.addScopes([driveScope], presenting: self!) { user, error in
if let error = error {
print("add scope failed, \(error), \(error.localizedDescription)")
}
guard let user = user else { return }
// Check if the user granted access to the scopes you requested.
if let scopes = user.grantedScopes,
scopes.contains(driveScope) {
print("Scope added")
print("NEW scopes: \(String(describing: scopes))")
self?.createGoogleDriveService(user: user)
}
}
}
}
}
}
func createGoogleDriveService(user: GIDGoogleUser) {
let service = GTLRDriveService()
service.authorizer = user.authentication.fetcherAuthorizer()
// dependency inject
modelController.googleAPIs = GoogleDriveAPI(service: service)
// Post notification after user successfully sign in
NotificationCenter.default.post(name: .signInGoogleCompleted, object: nil)
user.authentication.do { [weak self] authentication, error in
guard error == nil else { return }
guard let authentication = authentication else { return }
// Or, get an object that conforms to GTMFetcherAuthorizationProtocol for
// use with GTMAppAuth and the Google APIs client library.
let service = GTLRDriveService()
service.authorizer = authentication.fetcherAuthorizer()
// dependency inject
self?.modelController.googleAPIs = GoogleDriveAPI(service: service)
// Post notification after user successfully sign in
NotificationCenter.default.post(name: .signInGoogleCompleted, object: nil)
}
}
previous restore logic code
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print("SignIn failed, \(error), \(error.localizedDescription)")
} else {
print("Authenticate successfully")
let service = GTLRDriveService()
service.authorizer = user.authentication.fetcherAuthorizer()
// dependency inject
modelController.googleAPIs = GoogleDriveAPI(service: service)
// Post notification after user successfully sign in
NotificationCenter.default.post(name: .signInGoogleCompleted, object: nil)
}
}
The text was updated successfully, but these errors were encountered:
Yes, I make that call. And I found the reason why I cannot restore the login yesterday. I need to put code which creates google api service into restorePreviousSignInWithCallback: 's call back.
Before I only need to create google api service once in the delegate sign(didSignInFor) method, however now I need to put it in two places, one in signIn button and another in restorePreviousSignInWithCallback.
Hello, my iOS app can't restorePreviousSignIn in v6.0.1.
Before, I used
signIn:didSignInForUser:withError:
to restore user signIn state, and it works fine.Now, I follow your migration guide, to Move the logic from
signIn:didSignInForUser:withError:
to the callback block ofsignInWithConfiguration:presentingViewController:callback:
.Now, I put
signInWithConfiguration:presentingViewController:callback:
into Google signIn button, I could sign in but when I close and reopen my app,signInWithConfiguration:presentingViewController:callback:
is not triggered, then I couldn't restore the previous user signIn state.Is this the correct position it should be, how could I fix this issue? This version is quite new, I couldn't find related issue in internet, please help, guys.
previous restore logic code
The text was updated successfully, but these errors were encountered: