通过 google 加 ios 登录时应用程序崩溃
App crash when login through google plus ios
尝试集成google加登录。
但是当我写 let gpSignin = GIDSignIn.sharedInstance()
应用程序因错误而崩溃
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
这是我在按钮操作中的代码
@IBAction func googleClicked(_ sender: Any)
{
print(isConnectedToNetwork())
if isConnectedToNetwork()
{
let gpSignin = GIDSignIn.sharedInstance()
gpSignin?.scopes.append("https://www.googleapis.com/auth/plus.login")
gpSignin?.delegate = self
gpSignin?.uiDelegate = self
gpSignin?.clientID = "my client ID"
gpSignin?.shouldFetchBasicProfile = true
gpSignin?.shouldGroupAccessibilityChildren = true
if (gpSignin?.hasAuthInKeychain())!{
print("Signed In")
// GIDSignIn.sharedInstance().signInSilently()
gpSignin?.signIn()
// logInToBackendServerWithAuthIdToken()
} else{
print("Not Signed In")
gpSignin?.signOut()
gpSignin?.signIn()
// region.show(googleLoginView())
}
}
else
{
networkError()
}
}
请帮我解决这个问题。谢谢
你不能 edit/append 范围数组因为它是 NSArray。
试试改成下面的样子
@IBAction func googleClicked(_ sender: Any)
{
print(isConnectedToNetwork())
if isConnectedToNetwork()
{
if let gpSignin = GIDSignIn.sharedInstance() {
if gpSignin.scopes != nil {
let scopes = NSMutableArray(array: gpSignin.scopes)
scopes.add("https://www.googleapis.com/auth/plus.login")
if let convertedScopes = scopes as? [Any] {
gpSignin.scopes = convertedScopes
}
}
gpSignin.delegate = self
gpSignin.uiDelegate = self
gpSignin.clientID = "my client ID"
gpSignin.shouldFetchBasicProfile = true
gpSignin.shouldGroupAccessibilityChildren = true
if (gpSignin.hasAuthInKeychain())!{
print("Signed In")
// GIDSignIn.sharedInstance().signInSilently()
gpSignin.signIn()
// logInToBackendServerWithAuthIdToken()
} else{
print("Not Signed In")
gpSignin.signOut()
gpSignin.signIn()
// region.show(googleLoginView())
}
}
}
else
{
networkError()
}
}
尝试集成google加登录。
但是当我写 let gpSignin = GIDSignIn.sharedInstance()
应用程序因错误而崩溃
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
这是我在按钮操作中的代码
@IBAction func googleClicked(_ sender: Any)
{
print(isConnectedToNetwork())
if isConnectedToNetwork()
{
let gpSignin = GIDSignIn.sharedInstance()
gpSignin?.scopes.append("https://www.googleapis.com/auth/plus.login")
gpSignin?.delegate = self
gpSignin?.uiDelegate = self
gpSignin?.clientID = "my client ID"
gpSignin?.shouldFetchBasicProfile = true
gpSignin?.shouldGroupAccessibilityChildren = true
if (gpSignin?.hasAuthInKeychain())!{
print("Signed In")
// GIDSignIn.sharedInstance().signInSilently()
gpSignin?.signIn()
// logInToBackendServerWithAuthIdToken()
} else{
print("Not Signed In")
gpSignin?.signOut()
gpSignin?.signIn()
// region.show(googleLoginView())
}
}
else
{
networkError()
}
}
请帮我解决这个问题。谢谢
你不能 edit/append 范围数组因为它是 NSArray。
试试改成下面的样子
@IBAction func googleClicked(_ sender: Any)
{
print(isConnectedToNetwork())
if isConnectedToNetwork()
{
if let gpSignin = GIDSignIn.sharedInstance() {
if gpSignin.scopes != nil {
let scopes = NSMutableArray(array: gpSignin.scopes)
scopes.add("https://www.googleapis.com/auth/plus.login")
if let convertedScopes = scopes as? [Any] {
gpSignin.scopes = convertedScopes
}
}
gpSignin.delegate = self
gpSignin.uiDelegate = self
gpSignin.clientID = "my client ID"
gpSignin.shouldFetchBasicProfile = true
gpSignin.shouldGroupAccessibilityChildren = true
if (gpSignin.hasAuthInKeychain())!{
print("Signed In")
// GIDSignIn.sharedInstance().signInSilently()
gpSignin.signIn()
// logInToBackendServerWithAuthIdToken()
} else{
print("Not Signed In")
gpSignin.signOut()
gpSignin.signIn()
// region.show(googleLoginView())
}
}
}
else
{
networkError()
}
}