问题
To my knowledge, I have implemented Google Sign-in the exact way that Google states to do it on the website. It was working for a while, but now I cannot get it to work. I am receiving the error "The operation couldn’t be completed. (com.google.GIDSignIn error -4.)" and am unsure on what is happening. I have checked documentation for this specific error and ran through every possible idea on Stack Overflow. I appreciate any help in advance.
回答1:
As mentioned here http://cocoadocs.org/docsets/GoogleSignIn/4.0.0/Constants/GIDSignInErrorCode.html
typedef NS_ENUM(NSInteger, GIDSignInErrorCode ) {
kGIDSignInErrorCodeUnknown = -1,
kGIDSignInErrorCodeKeychain = -2,
kGIDSignInErrorCodeNoSignInHandlersInstalled = -3,
kGIDSignInErrorCodeHasNoAuthInKeychain = -4,
kGIDSignInErrorCodeCanceled = -5,
};
The error means that there are no auth tokens in the keychain, i.e., "User is not authorized". In this case, you signed in, then closed the app and reopened it.
To check if the user is authorized, use this piece of code:
func checkIfUserIsAuthorized() {
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
// User authorized before
GIDSignIn.sharedInstance().signInSilently()
} else {
// User not authorized open sign in screen
}
}
来源:https://stackoverflow.com/questions/37739557/google-sign-in-error-4