首页 > 解决方案 > 用于注册的 gmail 集成

问题描述

我正在尝试集成 gmailsignup 以获取用户详细信息。但不幸的是,应用程序崩溃了,在控制台中我越来越喜欢“原因:'您的应用程序缺少对以下 URL 方案的支持:com.googleusercontent.apps.184175093548-lsh99pp3c7hcglf12e2udcm0vcinjvd9' “如果有人帮助我解决它会很棒。在此先感谢。

//AppDelegate class, which I have written additionally.
import UIKit
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    var window: UIWindow?
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if let error = error {
            print("\(error.localizedDescription)")
        } else {
            // Perform any operations on signed in user here.
            let userId = user.userID                  // For client-side use only!
            let idToken = user.authentication.idToken // 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
            // ...
        }
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: \[UIApplication.LaunchOptionsKey: Any\]?) -> Bool {

        GIDSignIn.sharedInstance().clientID = "184175093548-lsh99pp3c7hcglf12e2udcm0vcinjvd9.apps.googleusercontent.com"
        GIDSignIn.sharedInstance().delegate = self
        let navigation = UINavigationController()
        let mainView = gmail(nibName: "gmail", bundle: nil) //ViewController = Name of your controller
        navigation.viewControllers = \[mainView\]
        self.window!.rootViewController = navigation
        self.window?.makeKeyAndVisible()
        // Override point for customization after application launch.
        return true

    }
    func application(_ app: UIApplication, open url: URL, options: \[UIApplication.OpenURLOptionsKey : Any\] = \[:\]) -> Bool {
        return GIDSignIn.sharedInstance().handle(url as URL?,
                                                 sourceApplication: options\[UIApplication.OpenURLOptionsKey.sourceApplication\] as? String,
                                                 annotation: options\[UIApplication.OpenURLOptionsKey.annotation\])
    }

//View controller class


import UIKit
import GoogleSignIn


class gmail: UIViewController,GIDSignInUIDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        var error: Error?



        let signinbtn = GIDSignInButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
        // Do any additional setup after loading the view.
        GIDSignIn.sharedInstance().uiDelegate=self
        signinbtn.center = view.center
        view.addSubview(signinbtn)
    }

    func signInWillDispatch(signIn: GIDSignIn!, error: NSError!) {
       // myActivityIndicator.stopAnimating()
    }


}

标签: iosswiftgoogle-signin

解决方案


推荐阅读