我使用google signIn Api,当我点击我的第一个视图上的登录按钮时,我得到了google webview页面,我可以登录自己并获取我的数据,之后我使用performe for segue访问第二种观点。 当我尝试在第二个视图中注销时,他将我的字符串“deco”打印出来,然后回到第一页。但是,当我再次尝试登录自己,他这个错误崩溃:AppDelegate send reponse swift3
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.'
我想注销功能没有工作,而且我不认为使用performe在的appDelegate SEGUE是最好的梅索德,你有别的东西吗? (期望通知)
我firstViewController
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()。断开()
我的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
}
当我不写GIDSignIn.sharedInstance()在我的视图控制器uiDelegate =自我,我崩溃与相同的消息,但我甚至不能登录一次 –