У меня возникла проблема с интеграцией входа в Google (5.0.2) в моем приложении. Приведенный ниже код может вызвать страницу входа, но не может получить обратный вызов. Интересно, если я что-то пропустил. Вот мой код, надеюсь, любой гений может помочь
`struct SocialLogin: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<SocialLogin>) -> UIViewController {
GIDSignIn.sharedInstance().delegate = context.coordinator
return UIViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<SocialLogin>) {
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject,GIDSignInDelegate {
var parent: SocialLogin
init(_ parent: SocialLogin) {
self.parent = parent
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
print("inside callback")
if error != nil {
Utility.hideProgress()
return
}else{
guard let authentication = user.authentication else { return }
print("Sign success by Google , get google info")
var tempUser = ProviderUser()
tempUser.userName = user.profile.name
tempUser.firstName = user.profile.givenName
tempUser.lastName = user.profile.familyName
tempUser.email = user.profile.email
tempUser.imgUrl = user.profile.imageURL(withDimension: 100)?.absoluteString
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
parent.firebaseLogin(credential, provider: "google",user:tempUser)
}
}
}
func attemptLoginGoogle() {
GIDSignIn.sharedInstance()?.presentingViewController = UIApplication.shared.windows.last?.rootViewController
GIDSignIn.sharedInstance()?.signIn()
}
`
var googleButton : some View {
Circle()
.fill(SwiftUI.Color.init(red: 219/255, green: 68/255, blue: 55/255))
.frame(width: 50, height: 50)
.overlay(
Image("icon-google")
.resizable()
.aspectRatio(contentMode: ContentMode.fit)
.frame(width: 30, height: 30)
).shadow(radius: 5)
.onTapGesture {
SocialLogin().attemptLoginGoogle()
}
}