我正尝试使用Google SignIn为使用Firebase的iOS应用验证用户身份。iOS:如果代理不是UIApplicationDelete,Google SignIn无法正常工作
在对GoogleSignInDependenies.framework
文件进行黑客入侵以删除重复的类并根据Firebase和Google登录网站上的说明添加代码之后,我开始工作。其中一部分是将GIDSignInProtocol
协议添加到应用程序委托并实现func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
方法中的代码。
我现在想要设置另一个类作为登录的委托,但是当我重新指派委托时,回调不会发生,我不能为我的生活找到原因。
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
print("App delegate Signin")
}
}
class FirebaseSecurity:NSObject, GIDSignInDelegate {
override init() {
super.init()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
// This works.
// GIDSignIn.sharedInstance().delegate = UIApplication.shared.delegate as! GIDSignInDelegate
// This doesn't work
GIDSignIn.sharedInstance().delegate = self
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
print("Security sign in")
}
}
}
轻弹两行安全init
来回,我可以得到日志说:
App delegate Signin
当我点击了GIDSignInButton
我加入到我的UI,但没有当我切换作为代表FirebaseSecurity
。
任何人都知道为什么这不起作用?
如果您在“FirebaseSecurity”对象中设置代理后立即“打印”某项内容,那么会在您点击“GIDSignInButton”之前或之后显示该行吗? –
谢谢迈克尔,发现了这个问题,它就是我。请参阅下面的答案。 – drekka