2016-11-10 37 views
1

docs herefacebookSDK,Swift3和AppDelegate中处理登录

我已经实现了登录按钮优良,应用假冒的fblogin完成很好,但后,我登录我得到回传给应用程序和控制台始终读

“用户取消登陆”

各地的网络一些网站的搜索表明,我需要添加一些然而AppDelegate.Swift的文档只对Objective-C的项目代码。

this guy's guide但我认为这是迅速的1.x

改变稍微照顾NSURL的下降我使用的书面:

import UIKit 
import FBSDKCoreKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 
     return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
    } 

    func application(application: UIApplication, 
        open url: URL, 
        sourceApplication: String?, 
        annotation: AnyObject?) -> Bool { 
     return FBSDKApplicationDelegate.sharedInstance().application(
      application, 
      openURL: url, 
      sourceApplication: sourceApplication, 
      annotation: annotation) 
    } 
    func applicationWillResignActive(_ application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(_ application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(_ application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(_ application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
     FBSDKAppEvents.activateApp() 
    } 

    func applicationWillTerminate(_ application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 

但我得到错误“的应用(:的OpenURL:sourceApplication:注释:)”已更名为‘应用程序(:开:sourceApplication:注释:)’

任何人有任何想法如何得到这个代表团的工作和GE从Facebook登录返回正确的东西?

回答

0

你需要做出的appdelegate如下变化:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

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

与FacebookCore.ApplicationDelegate(我希望它将被命名为FBApplicationDelegate),因为它遵循

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { 
    return FacebookCore.ApplicationDelegate.shared.application(app, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey] ?? []) 
} 

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    return FacebookCore.ApplicationDelegate.shared.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

参考更多链接: https://github.com/facebook/facebook-sdk-swift/issues/35

+0

绝对的传说,我欠你一杯啤酒。 –