Facebookログインを行い、もしログインユーザーのメールアドレスが取得できなかったら、アラートを出すようにします。
しかし、Alertを表示する際に、whose view is not in the window hierarchy!のエラーが出ます。
Facebookログインする際に、一度Facebookアプリに遷移し、認証してから元のアプリに戻って続きの処理を行いますが、遷移の直後ではAlertを表示できないようです。
swift
1@IBAction func FBLogin(_ sender: Any) { 2 manager.login(readPermissions: ["public_profile","email"], fromViewController: self) { (success) in 3 if success 4 { 5 print("Logged in successfully with access token : (self.manager.currentToken!.tokenString)") 6 7 WTFacebookManager.sharedInstance.getBasicInfo(permissionList: ["name", "email"]) { (info) in 8 9 guard let userInfo = info 10 else 11 { 12 print("Error in requesting information") 13 return 14 } 15 16 print(userInfo["email"]) 17 if userInfo["email"] != nil { 18 // 成功時の処理 19 } else { 20 let Alert: UIAlertController = UIAlertController(title:"ログインエラー",message:"Facebookからメールアドレスを取得できません。",preferredStyle: .alert) 21 let CloseAction = UIAlertAction(title: "閉じる", style: .default) { 22 action in 23 } 24 Alert.addAction(CloseAction) 25 self.present(Alert, animated: true, completion: nil) // エラー 26 } 27 } 28 } 29 else 30 { 31 print("Error in logging in") 32 } 33 } 34 }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。