7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Swift] FacebookSDK iOS 4.4 で logout した後に loginViewControllerに戻って再度loginしても画面遷移が行われない場合

Posted at

TDLR

  • 作業メモ・備忘録なので状況がよくわからないかもしれません。
  • モーダルを出したらちゃんと消そうということ。

状況

Storyboardを2つ用意しています。

    1. Login周り
    1. その他メイン用

FacebookSDK iOS 4.4を使ってログインして、メインのStoryboardに遷移

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
 ・
 ・
 // accessTokenとか諸々をアプリ用サーバーに登録したり、RealmやUserDefaultsなんかに保存したり。。。
 ・
 ・
 // メインのStoryboardのInitialViewControllerへ遷移
     var storyboard: UIStoryboard = UIStoryboard(name:"Main", bundle: nil)
      var nextVC: UIViewController = storyboard.instantiateInitialViewController() as! UIViewController
     self.navigationController?.pushViewController(nextVC, animated: true)
}

FBSDKLoginManager().logOut()でログアウトして、ログイン用のStoryboardに戻る

FBSDKLoginManager().logOut()
let storyboard = UIStoryboard(name: "Login", bundle: nil)
let nextVC = storyboard.instantiateInitialViewController() as! UIViewController
self.presentViewController(nextVC, animated: true, completion: nil)

結果

だいたい以上の様な流れのコードをRunしてみました。

  • FBログイン→ログアウト→FBログイン
    ↑をしたところ、SafariのFBログイン画面でConfirmした後、アプリに戻りましたが、ログイン画面のまま遷移しませんでした。

対応

ログアウト後の画面がモーダルになっていたので、以下のコードを画面遷移に追加しました。

self.dismissViewControllerAnimated(true, completion: nil)

これによってうまく動きました。

疑問

Facebookログインとは別にOAuth2を用いたソーシャルログイン機能も実装していまして、そちらは上記の対応をしなくても問題なく動作していました。

FacebookSDKの中身を覗いても特別複雑な処理はしていませんでした。

同じ画面遷移のコードでどうして動作に差が生まれたのかがわかりません。

画面遷移について

こちらが参考になりました

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?