2017-01-11 13 views
0

私は自分のアプリでFacebookのログインを使用しています。私は依存関係をインポートするポッドを持っています。私はポッドFBSDKCoreKitとポッドFBSDKLoginKitをポッドファイルに使用しています。Facebook Sign Inでの投稿

そして、私のコードは私のViewControllerで

// AppDelegate

import FBSDKCoreKit 
import FBSDKLoginKi 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    //Realm migration 
    realmMigration() 
    window = UIWindow(frame: UIScreen.main.bounds) 

    let navigationBarAppearace = UINavigationBar.appearance() 
    navigationBarAppearace.tintColor = UIColor.lightGray 
    navigationBarAppearace.barTintColor = UIColor.darkGray 

    let landingViewObj = LandingView(nibName: (UIDevice.current.userInterfaceIdiom == .pad ? "LandingView" : "LandingView"), bundle: nil) 
    navigationController = UINavigationController(rootViewController: landingViewObj) 

    self.window?.rootViewController = navigationController 
    self.window?.makeKeyAndVisible() 

    IQKeyboardManager.sharedManager().enable = true 

    FIRApp.configure() 

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

    return true 
} 

@available(iOS 9.0, *) 
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) 
    -> Bool 
{ 
    let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: "UIApplicationOpenURLOptionsKey", annotation: [:]) 

    let googleDidHandle = GIDSignIn.sharedInstance().handle(url, 
                  sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, 
                  annotation: [:]) 

    return googleDidHandle || facebookDidHandle 
} 

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool 
{ 

    let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation) 

    let googleDidHandle = GIDSignIn.sharedInstance().handle(url, 
                  sourceApplication: sourceApplication, 
                  annotation: annotation) 

    return googleDidHandle || facebookDidHandle 
} 

、私のFacebookのログインカスタムボタンアクションで

import FBSDKCoreKit 
import FBSDKLoginKit 

@IBAction func facebookSigninAction(_ sender: Any) 
{ 
let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"first_name,email, picture.type(large)"]) 

     graphRequest.start(completionHandler: { (connection, result, error) -> Void in 

      if ((error) != nil) 
      { 
       print("Error: \(error)") 
      } 
      else 
      { 
       let data:[String:AnyObject] = result as! [String : AnyObject] 
       print(data) 

      } 
     }) 
} 

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError?) 
{ 
    if let error = error 
    { 
     print(error.localizedDescription) 
     return 
    } 
    // ... 
} 

とでありますpl ISTファイル私は

<key>FacebookAppID</key> 
<string>349152685470803</string> 
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fbapi</string> 
    <string>fbauth</string> 
    <string>fbauth2</string> 
    <string>fb</string> 
    <string>fb-messenger-api20140430</string> 
</array> 
<key>CFBundleURLTypes</key> 
<array> 
    <dict> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>CFBundleURLName</key> 
     <string>facebook</string> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>fb349152685470803</string> 
     </array> 
    </dict> 
    <dict> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>CFBundleURLName</key> 
     <string></string> 
     <key>CFBundleURLSchemes</key> 
     <array> 
<string>com.googleusercontent.apps.316518738586-d36rr39tpllb40056330jrra12v1tn86</string> 
     </array> 
    </dict> 
</array> 

次のものを追加している私のPROBは、私は私のログに次のエラーを取得するとアプリが、私は結果をフェッチすることがあったクロージャを呼び出すことはありませんです。

2017-01-11 17:10:21.047 MyApp[7525:1384017] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" 

権限を要求して結果オブジェクトを読み取る方法はありますか?

+0

同じ問題がありました。設定にバンドルIDを追加します。だからfacebookの設定で私はプラットフォーム "IOS"を追加し、私のバンドルIDを与え、それは私のために働いた。 – Cliffordwh

+0

@Cliffordwh私はすでにそれをしています。まだ仕事はありませんでした。 – Mano

+0

plistファイルにFacebookDisplayNameがあることを確認してください。また、バンドルIDをダブルチェック! ( 大文字と小文字を区別 ) – Cliffordwh

答えて

0

enter image description hereこのようなバンドルIDを追加する必要があります。

<dict> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>CFBundleURLName</key> 
     <string>*** Add BundleId</string> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string> fb349152685470803 </string> 
     </array>