问题
I have a view controller on a navigation stack (2nd child).
Controller is setup as GIDSignInDelegate and GIDSignInUIDelegate.
After triggering sign-in, every delegate method expected to be called, is called, except for:
func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
and
func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!)
Note that in viewDidLoad I have assigned the view controller to be the delegate and ui delegate.
Also, after dismissing the Google Sign-In view, my current view controller is automatically popped off the navigation stack (?????)
What is causing this?
回答1:
If the issue is occurring on iOS 11 and higher then I found this explanation in the changelog document of the framework: https://cocoapods.org/pods/GoogleSignIn/changelog
Entry from 2017-10-17 -- v4.1.1 states:
Fixes an issue that GIDSignInUIDelegate's signInWillDispatch:error: was not called on iOS 11. Please note that it is intended that neither signIn:presentViewController: nor signIn:dimissViewController: is called on iOS 11 because SFAuthenticationSession is not presented by the app's view controller.
According to the above explanation signInWillDispatch:error is indeed called, but signIn:presentViewController: and signIn:dimissViewController: are intentionally not called because the underlying SFAuthenticationSession presents and dismisses sign-in flow through private API rendering the two callback methods useless. I suppose these methods are remaining in the GIDSignInUIDelegate protocol solely for the sake of backwards compatibility with iOS 10 where SFAuthenticationSession was not used and the sign in flow could be presented and dismissed from a particular view controller.
However even though the two methods never get called on iOS 11 and higher they still need to be implemented when the delegate object is not a subclass of UIViewController, otherwise the app will crash. Obviously it's not very logical to have methods implemented which do nothing...
On a side note, Google could do a better job at updating their documentation because now it is rather misleading: https://developers.google.com/identity/sign-in/ios/api/protocol_g_i_d_sign_in_u_i_delegate-p#a2b265097a3c78e7f82d57b2ccda11c39
来源:https://stackoverflow.com/questions/52687644/gidsigninuidelegate-methods-to-getting-called