Ios 使用Swift登录Facebook后加载另一个ViewController

Ios 使用Swift登录Facebook后加载另一个ViewController,ios,swift,uiviewcontroller,facebook-login,Ios,Swift,Uiviewcontroller,Facebook Login,在使用swift成功登录Facebook后,我正在尝试加载另一个视图控制器。我一直在关注这篇博文: 我配置了一个名为“redirectAfterLogin”的segue,并尝试使用performsgueWithIdentifier 下面可以看到我的ViewController.swift和AppDelegate.swift文件。不知怎的,我错过了一些东西。有什么建议吗 ViewController.swift AppDelegate.swift 这是我登录模拟器后的输出: 2016-02-11

在使用swift成功登录Facebook后,我正在尝试加载另一个视图控制器。我一直在关注这篇博文:

我配置了一个名为“redirectAfterLogin”的segue,并尝试使用performsgueWithIdentifier

下面可以看到我的ViewController.swift和AppDelegate.swift文件。不知怎的,我错过了一些东西。有什么建议吗

ViewController.swift

AppDelegate.swift

这是我登录模拟器后的输出:

2016-02-11 14:43:49.712 TMR-Prototype1[22260:3512428]-canOpenURL:URL失败:“fbauth2:/”-错误:“(空)”

2016-02-11 14:43:49.717 TMR-Prototype1[22260:3512428]-canOpenURL:URL失败:“fbauth2:/”-错误:“(空)”

这是截图。它卡在第一个viewcontroller上:

我还将我的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>

CfBundledDevelopmentRegion
EN
Cbundlexecutable
$(可执行文件名称)
CbundleIdentifier
$(产品\捆绑包\标识符)
CbundleInfo字典版本
6
CFBundleName
$(产品名称)
CbundlePackageType
应用
CbundleShortVersionString
1
CFBundleSignature
????
循环流化床锅炉
1.
LSREQUIRESPHONEOS
UILaunchStoryboardName
发射屏
UIMainstryBoardFile
主要
UIRequiredDeviceCapabilities
armv7
UI支持接口方向
UIInterfaceOrientationPortrait
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight
UI支持界面方向~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientation上下方向图
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight
CbundleurlTypes
循环流化床锅炉方案
fbXXXYYYZZZ
FacebookAppID
xxxyyzzz
FacebookDisplayName
TMR
NSAppTransportSecurity
NSExceptionDomains
facebook.com
n包括多个域
N第三方例外要求转发保密
fbcdn.net
n包括多个域
N第三方例外要求转发保密
akamaihd.net
n包括多个域
N第三方例外要求转发保密
LSApplicationQueriesSchemes
fbapi
fb messenger api
fbauth2
fbshareextension

您应该将
fbsdkloginbuttonelegate
实现到您的
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
    }
}

您应该将
fbsdkloginbuttonelegate
实现到
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
    }
}

我好像忘了设置登录按钮的委托。谢谢,我好像忘了设置登录按钮的委托。谢谢
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
    }
}