###実現したいことと困っていること
現在アプリ開発にて、Facebookログインを実装しようとしているのですが、
以下の2点がうまくできず、ご意見をいただければと思っております。
・Facebookログイン後の画面遷移
・Firebaseでユーザデーターを取得する
下記のコードで実装してみているのですが、問題があれば教えていただきたいです。
宜しくお願い申し上げます。
###該当のコード(Appdelegate.swift)
swift
1import UIKit 2 3import Firebase 4import FirebaseAuth 5import FBSDKCoreKit 6import FBSDKLoginKit 7 8@UIApplicationMain 9class AppDelegate: UIResponder, UIApplicationDelegate{ 10 11 var window: UIWindow? 12 13 func application(_ application: UIApplication, 14 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) 15 -> Bool { 16 17 FirebaseApp.configure() 18 19 FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 20 21 return true 22 } 23 24 25 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 26 let handled:Bool = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options) 27 return handled 28 } 29
###該当のコード(Viewcontroller.swift)
swift
1 2import UIKit 3import FirebaseAuth 4import FBSDKCoreKit 5import FBSDKLoginKit 6 7class FacebookLoginViewController: UIViewController { 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 // Do any additional setup after loading the view. 13 } 14 15 override func didReceiveMemoryWarning() { 16 super.didReceiveMemoryWarning() 17 // Dispose of any resources that can be recreated. 18 } 19 20 21 @IBAction func signInTapped(_ sender: Any) { 22 23 let loginManager: FBSDKLoginManager = FBSDKLoginManager() 24 loginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends"], from: self) { (result, error) in 25 if (error != nil) { 26 // エラーが発生した場合 27 print("Process error") 28 } else if (result?.isCancelled)! { 29 // ログインをキャンセルした場合 30 print("Cancelled") 31 } else { 32 // その他 33 print("Login Succeeded") 34 let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString) 35 } 36 37 } 38 39 func signIn(credential:AuthCredential){ 40 41 Auth.auth().signIn(with: credential) { (user, error) in 42 if let error = error { 43 print("error:(error)") 44 return 45 } else { 46 _ = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString) 47 self.performSegue(withIdentifier: "SignedInSegue", sender: nil) 48 } 49 return 50 } 51 } 52 53 } 54} 55 56 57
あなたの回答
tips
プレビュー