質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1523閲覧

swift3でFirebaseサインイン後にサインインのViewControllerで処理

yamayamak

総合スコア131

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/12/31 13:15

swift3でGoogleアカウント連携を開発してます。
GoogleアカウントでFirebaseサインインまではできているのですが、サインイン後の処理をAppDelegateで以下のように記載しています。
Firebaseサインイン直後に、サインイン画面のloginViewControllerで戻って処理したいのですがやり方がわかりませんので、ご教授ください。
func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!)
で処理するのかと思いました、以下のFirebaseサイン処理する前に処理され正常に動作しません。

AppDelegateで以下の処理をしています。

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) { if let error = error { print(error.localizedDescription) return } guard let authentication = user.authentication else { return } let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken) Auth.auth().signIn(with: credential) { (user, error) in if let error = error { print(error.localizedDescription) return } print("User is signed in") let storyboard = UIStoryboard(name: "Main", bundle: nil) let mainVC = storyboard.instantiateViewController(withIdentifier: "main") as! mainViewController self.window?.rootViewController?.present(mainVC, animated: true, completion: { print("change") }) } }

loginViewControllerで以下の処理を記載するも、上記の前に処理されログイン状態で処理されません。

func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) { // サインウインドウが閉じたあとの処理 print("DEBUG:GIDSignIn dismiss!!!") if let user = Auth.auth().currentUser { hogehogeJob() } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

結局、AppDelegateからloginViewControllerのメソッドを呼び出すことにしました。

AppDelegateのClass内直下

var viewController: loginViewController!

AppDelegateのメソッド内でmainViewControllerへ遷移する処理を以下へ書き換え

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate appDelegate.viewController.メソッド名()

loginViewControllerのviewDidLoad内

var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate appDelegate.viewController = self

投稿2017/12/31 14:23

編集2017/12/31 15:34
yamayamak

総合スコア131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問