2016-07-28 2 views
2

J'ai essayé d'implémenter la connexion Facebook avec un bouton de connexion personnalisé, j'ai complété toutes les étapes de configuration et quand j'appuie sur le bouton, la vue web est présente et demande l'autorisation. Cependant, si j'appuie sur Terminé (en haut à gauche du contrôleur de vue Web), le bloc d'achèvement est appelé mais lorsque j'appuie sur Annuler ou OK, le contrôleur de vue Web est fermé mais le bloc d'achèvement n'est jamais appelé? enter image description here Voici le code je:Facebook login bloc d'achèvement non appelé

let fbLoginManager = FBSDKLoginManager() 
    fbLoginManager.loginBehavior = .Native 
    fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) in 
     // put a breakpoint here but it won't stop here if I tap OK 
     if error != nil { 
      print(error.localizedFailureReason) 
     } else if result.isCancelled { 
      // dismiss view 
     } else { 
      let token = result.token.tokenString 
      // do something with the token 
     } 
    } 

EDIT 1

Voici la méthode url ouverte AppDelegate:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { 
    return application(app, openURL: url, sourceApplication: nil, annotation: [:]) 
} 
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    if url.scheme == Key.FACEBOOK_URL_SCHEME { 
     let handled = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
     return handled 
    } 
    let dynamicLink = FIRDynamicLinks.dynamicLinks()?.dynamicLinkFromCustomSchemeURL(url) 
    if let dynamicLink = dynamicLink { 
     if let url = dynamicLink.url { 
      if let paths = url.pathComponents{ 
       if paths.count > 2 { 
        let slug = paths[2] 
        if let book = AppManager.instance.findBookBySlug(slug) { 
         // Open detail book 
         self.openDetailBook(book) 
        } else { 
         self.openDetailBookWithSlug(slug) 
        } 
       } 
      } 
     } 
    } 
    if url.scheme == Key.DEEP_LINK_URL_SCHEME { 
     if let paths = url.pathComponents, host = url.host { 
      if host == "truyen" { 
       if paths.count > 1 { 
        let slug = paths[1] 
        if let book = AppManager.instance.findBookBySlug(slug) { 
         // Open detail book 
         self.openDetailBook(book) 
        } else { 
         self.openDetailBookWithSlug(slug) 
        } 
       } 
      } 
     } 
    } 
    return true 
} 
+0

peut vous envoyer ur méthode url ouverte? –

+0

pls regarder http://stackoverflow.com/questions/32299271/facebook-sdk-login-never-calls-back-my-application-on-ios-9. SVP suivez la réponse suggérée par David. –

+0

vous devez changer l'application de retour (app, openURL: url, sourceApplication: nil, annotation: [:]) dans votre première méthode url ouverte –

Répondre

2

Si jamais vous êtes confrontés à cette situation, déboguez-la vous-même car Facebook SDK est open source. La fenêtre que vous voyez est la SFSafariViewController. Lorsque vous appuyez sur l'un de ces boutons, le rappel sera géré par le SFSafariViewController. Recherchez les méthodes SFSafariViewControllerdelegate dans le sdk Facebook. Mettez un point d'arrêt après avoir appelé le code de connexion et allez pas à pas, il vous mènera à la classe qui utilise SFSafariViewController.

Dans l'une de ces méthodes delegate, vous trouverez un appel à la méthode d'URL ouverte. Implémentez la même méthode d'URL ouverte dans la méthode de délégation d'application.

Dans votre cas, le problème serait d'utiliser une mauvaise méthode openURL. CORRECTE shud être

func application(application: UIApplication,openURL url: NSURL, options: [String: AnyObject]) -> Bool { 
return FBSDKApplicationDelegate.sharedInstance().application(application, 
    openURL: url, 
    sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, 
    annotation: options [UIApplicationOpenURLOptionsAnnotationKey]) 
} 
+0

Cela a fonctionné! Merci pour votre temps. – JozackOverFlow

0

Ajouter méthode ouverte url dans votre fichier AppDelegate.m et mettre le point d'arrêt dans cette méthode

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 
    return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; 
} 
+0

Merci pour votre réponse, mais je l'ai fait ajouter la méthode, j'ai système multiple donc il y a une clause if pour le régime Facebook, mais il a fait sauter dans ce si url.scheme == {Key.FACEBOOK_URL_SCHEME let = FBSDKApplicationDelegate traitées. sharedInstance(). application (application, openURL: URL, sourceApplication: sourceApplication, annotation: annotation) retour traité } – JozackOverFlow

1

Swift 3, La suppression de cette méthode a fonctionné pour moi,

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 
    return application(app, open: url, sourceApplication: nil, annotation: [:]) 
}