2016-02-11 1 views
0

Я пытаюсь загрузить другой контроллер представления после успешного входа в систему Facebook с быстрым. Я после этого блога: http://studyswift.blogspot.com.tr/2016/01/facebook-sdk-and-swift-create-facebook.htmlЗагрузить еще один ViewController после Facebook Вход с Swift

Я настроил SEGUE под названием «redirectAfterLogin» и пытался использовать performSegueWithIdentifier

Ниже вы можете увидеть мои ViewController.swift и AppDelegate.swift файлы. Почему-то я чего-то не хватает. Какие-либо предложения?

ViewController.swift

import UIKit 
import FBSDKLoginKit 

class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     let loginButton = FBSDKLoginButton() 
     loginButton.center = view.center 
     view.addSubview(loginButton) 
     //self.performSegueWithIdentifier("redirectAfterLogin", sender: self) 

    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


    /* 
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result:FBSDKLoginManagerLoginResult!, error: NSError!) { 
     if error == nil { 
      print("login complete") 
      self.performSegueWithIdentifier("redirectAfterLogin", sender: self) 
     } 
     else { 
      print(error.localizedDescription) 
     } 

    } 
    */ 

} 

AppDelegate.swift

import UIKit 

import FBSDKCoreKit 
import FBSDKLoginKit 
import FBSDKShareKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    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(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 
     FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
     return true 
    } 

    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 throttle down OpenGL ES frame rates. 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 inactive 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:. 
    } 


} 

И это выход после того, как я вошел в имитатор:

2016-02-11 14:43:49.712 TMR-Prototype1[22260:3512428] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

2016-02-11 14:43:49.717 TMR-Prototype1[22260:3512428] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

И вот скриншот. Он застрял на первом ViewController: enter image description here

Я также отредактировал мой файл Info.plist как:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>CFBundleDevelopmentRegion</key> 
    <string>en</string> 
    <key>CFBundleExecutable</key> 
    <string>$(EXECUTABLE_NAME)</string> 
    <key>CFBundleIdentifier</key> 
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 
    <key>CFBundleInfoDictionaryVersion</key> 
    <string>6.0</string> 
    <key>CFBundleName</key> 
    <string>$(PRODUCT_NAME)</string> 
    <key>CFBundlePackageType</key> 
    <string>APPL</string> 
    <key>CFBundleShortVersionString</key> 
    <string>1.0</string> 
    <key>CFBundleSignature</key> 
    <string>????</string> 
    <key>CFBundleVersion</key> 
    <string>1</string> 
    <key>LSRequiresIPhoneOS</key> 
    <true/> 
    <key>UILaunchStoryboardName</key> 
    <string>LaunchScreen</string> 
    <key>UIMainStoryboardFile</key> 
    <string>Main</string> 
    <key>UIRequiredDeviceCapabilities</key> 
    <array> 
     <string>armv7</string> 
    </array> 
    <key>UISupportedInterfaceOrientations</key> 
    <array> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 
    <key>UISupportedInterfaceOrientations~ipad</key> 
    <array> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationPortraitUpsideDown</string> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 

    <!-- following stuff added by me as for facebook login --> 

    <key>CFBundleURLTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>fbXXXYYYZZZ</string> 
      </array> 
     </dict> 
    </array> 
    <key>FacebookAppID</key> 
    <string>XXXYYYZZZ</string> 

    <key>FacebookDisplayName</key> 
    <string>TMR</string> 

    <key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>facebook.com</key> 
      <dict> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
       <false/> 
      </dict> 
      <key>fbcdn.net</key> 
      <dict> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
       <false/> 
      </dict> 
      <key>akamaihd.net</key> 
      <dict> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
       <false/> 
      </dict> 
     </dict> 
    </dict> 

    <key>LSApplicationQueriesSchemes</key> 
    <array> 
     <string>fbapi</string> 
     <string>fb-messenger-api</string> 
     <string>fbauth2</string> 
     <string>fbshareextension</string> 
    </array> 

</dict> 
</plist> 

ответ

4

Вы должны осуществлять FBSDKLoginButtonDelegate к вашему ViewController, и включают в себя методы делегата.

class ViewController: UIViewController, FBSDKLoginButtonDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     let loginButton = FBSDKLoginButton() 
     loginButton.center = view.center 
     loginButton.delegate = self // Remember to set the delegate of the loginButton 
     view.addSubview(loginButton) 
    } 

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 
     /* 
      Check for successful login and act accordingly. 
      Perform your segue to another UIViewController here. 
     */ 
    } 

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) { 
     // Actions for when the user logged out goes here 
    } 
} 
+0

Кажется, я забыл установить делегат кнопки входа. благодаря –

Смежные вопросы