【发布时间】:2017-07-03 03:46:51
【问题描述】:
我使用 google signIn Api,当我在我的第一个视图上单击我的登录按钮时,我得到了 google webview 页面,在我使用 performe for segue 访问第二个视图之后,我可以记录自己并获取我的数据。 当我尝试在第二个视图中注销时,他打印我的字符串“deco”,然后我回到我的第一页。但是当我再次尝试登录自己时,他会因以下错误而崩溃:
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'uiDelegate 必须是 |UIViewController|或实现 |signIn:presentViewController:| 和 |signIn:dismissViewController:|方法来自 |GIDSignInUIDelegate|。'
我认为注销功能不起作用,而且我不认为在 appDelegate 中使用 performe for segue 是最好的方法,你用别的方法吗? (期待通知)
我的第一个视图控制器
class ViewController: UIViewController, GIDSignInUIDelegate{
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func btn(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}}
在我的第二个观点中,我有同样的事情,唯一的变化是 GIDSignIn.sharedInstance().disconnect()
我的 appDelegate 包含
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
var configureError : NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
if (configureError != nil)
{
print("We have an error ! \(configureError)")
}
else
{
print("Google ready sir !")
}
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(
url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.accessToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
print("userId =>\(userId)")
print("idToken =>\(idToken)")
print("fullName =>\(fullName)")
print(" familyName=>\(familyName)")
print(" givenName=>\(givenName)")
print("email =>\(email)")
print("info => \(user.authentication)")
guard let rvc = self.window?.rootViewController as? ViewController
else {
return
}
rvc.performSegue(withIdentifier: "test", sender: nil)
} else {
print("\(error.localizedDescription)")
}
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!)
{
print("Deco")
}
// Other func not usefull
}
【问题讨论】:
标签: ios swift swift3 appdelegate google-signin