谷歌登录页面IOS SwiftUI(5.0.2)下没有键盘弹出窗口



>我在应用程序下集成谷歌登录 (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()
}
}

我已经为谷歌登录实现了相同的流程。

您需要在主视图中的某个位置调用/初始化SocialLogin((。

请看下面的实现,我是如何实现的。

=====

在主内容视图中,我已经传递了SocialLogin((作为按钮的视图

Button(action: SocialLogin().attemptLoginGoogle(), label: {
SocialLogin()
})

=====

ONSocialLogin((返回一些 UI

func makeUIView(context: UIViewRepresentableContext<SocialLogin>) -> UIView {
GIDSignIn.sharedInstance()?.delegate = context.coordinator
let imageView = UIImageView()
imageView.image = UIImage(named: "YOUR IMAGE NAME")
imageView.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
imageView.contentMode = .scaleAspectFit
return imageView
}

然后您将能够在结构 SocialLogin: UIViewControllerRepresentable {

它对我有用

最新更新