前提
Swiftで開発を始めた者です。
FirebaseでGoogle認証をしたく、公式ドキュメントを参考にしながら進めていたのですが、Type of expression is ambiguous without more contextと表示されて躓いています。どのようにすれば対処できるでしょうか。ご教示いただきたいです。
発生している問題・エラーメッセージ
Type of expression is ambiguous without more context
該当のソースコード
AppDelegate.swift
1import UIKit 2import FirebaseCore 3import GoogleSignIn 4import FirebaseAuth 5 6 7@main 8class AppDelegate: UIResponder, UIApplicationDelegate { 9 10 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 11 // Override point for customization after application launch. 12 13 let ud = UserDefaults.standard 14 let firstLunchKey = "firstLunch" 15 let firstLunch = [firstLunchKey: true] 16 ud.register(defaults: firstLunch) 17 18 FirebaseApp.configure() 19 20 return true 21 } 22 23 // MARK: UISceneSession Lifecycle 24 25 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 26 // Called when a new scene session is being created. 27 // Use this method to select a configuration to create the new scene with. 28 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 29 } 30 31 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 32 // Called when the user discards a scene session. 33 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 34 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 35 } 36 37 func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool { 38 return GIDSignIn.sharedInstance.handle(url) 39 } 40 41 42}
loginViewController.swift
1import UIKit 2import FirebaseCore 3import GoogleSignIn 4import FirebaseAuth 5 6 7class loginViewController: UIViewController { 8 9 @IBOutlet weak var signInButton: GIDSignInButton! 10 11 override func viewDidLoad() { 12 super.viewDidLoad() 13 14 // Do any additional setup after loading the view. 15 } 16 17 @IBAction func didTapSoginButton(_ sender: Any) { 18 auth() 19 } 20 21 @IBAction func loginButton(_ sender: Any) { 22 } 23 24 @IBAction func registerButton(_ sender: Any) { 25 } 26 27 private func auth() { 28 guard let clientID = FirebaseApp.app()?.options.clientID else { return } 29 let config = GIDConfiguration(clientID: clientID) 30 31//この下の一行に出てます 32 GIDSignIn.sharedInstance.signIn(with: config, presenting: self) { [unowned self] user, error in 33 if let error = error { 34 print("GIDSignInError: \(error.localizedDescription)") 35 return 36 } 37 38 guard let authentication = user?.authentication, 39 let idToken = authentication.idToken else { return } 40 41 let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken) 42 self.login(credential: credential) 43 } 44 } 45 46 private func login(credential: AuthCredential) { 47 print("ログイン完了") 48 } 49 50}
あなたの回答
tips
プレビュー