我使用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 =自我,我崩潰與相同的消息,但我甚至不能登錄一次 –