2015-12-30 53 views
0

我已經花費了很長時間來解決這個問題,但是在登錄我的Facebook帳戶併爲我的應用程序授予使用權限之後,除了左上角的完成按鈕被擊中之外。當我點擊完成按鈕後,一切正常,但我用其他應用程序進行了測試,我不應該這樣做。我究竟做錯了什麼。我有最新的Facebook sdk 4.6我相信,我認爲我的.plist是正確的,並且我已經添加了所有框架。必須在ios 9上登錄到Facebook後點擊「完成」按鈕

<key>CFBundleURLTypes</key> 
<array> 
    <dict> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>fb497638107079749</string> 
     </array> 
    </dict> 
</array> 
<key>FacebookAppID</key> 
<string>NUMBER</string> 
<key>FacebookDisplayName</key> 
<string>What's Up</string> 
<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>facebook.com</key> 
     <dict> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <key>NSExceptionRequiresForwardSecrecy</key> 
      <false/> 
     </dict> 
     <key>fbcdn.net</key> 
     <dict> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <key>NSExceptionRequiresForwardSecrecy</key> 
      <false/> 
     </dict> 
     <key>akamaihd.net</key> 
     <dict> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <key>NSExceptionRequiresForwardSecrecy</key> 
      <false/> 
     </dict> 
    </dict> 
</dict> 
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fbapi</string> 
    <string>fbapi20130214</string> 
    <string>fbapi20130410</string> 
    <string>fbapi20130702</string> 
    <string>fbapi20131010</string> 
    <string>fbapi20131219</string> 
    <string>fbapi20140410</string> 
    <string>fbapi20140116</string> 
    <string>fbapi20150313</string> 
    <string>fbapi20150629</string> 
    <string>fbauth</string> 
    <string>fbauth2</string> 
    <string>fb-messenger-api20140430</string> 
</array> 
<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fbapi</string> 
    <string>fb-messenger-api</string> 
    <string>fbauth2</string> 
    <string>fbshareextension</string> 
</array> 
</dict> 

screen with done button

Previous screen

功能登錄按鈕不運行,直到我打的完成按鈕

import UIKit 
import FBSDKLoginKit 

    class ViewController: UIViewController, FBSDKLoginButtonDelegate { 
    //@IBOutlet weak var loginButton: FBSDKLoginButton! 

@IBOutlet weak var loginButton: FBSDKLoginButton! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    if(FBSDKAccessToken.currentAccessToken() == nil){ 
     print("user is not logged in") 

    }else{ 
     print("user is logged in") 
    } 

    loginButton.delegate = self 
    loginButton.readPermissions = ["public_profile","email","user_friends"] 
    print("this is all good") 
} 

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


func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 
    print("clicked") 

    if (error == nil){ 
     print("Login Complete") 


      print("i am in the if") 



     self.performSegueWithIdentifier("showNew", sender: self) 
    }else{ 
     print(error.localizedDescription) 
    } 


} 


func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) { 

    print("user logged out") 
} 
+0

一旦重置模擬器,然後重試。 –

+0

我添加了代碼,但我檢查了一個教程,這正是另一個人對ios 8所做的,但是我找不到ios 9的教程,而且我很困擾objective-c,所以文檔沒有多大幫助。 – user2581628

+0

http://stackoverflow.com/questions/28248182/ios-swift-and-facebook-sdk檢查此鏈接。 –

回答

0

據我所看到的,你在您的pList中有2個NSTransportSecurity密鑰。請按照如下所示將它們配置爲一個。

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>akamaihd.net</key> 
     <dict> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
      <false/> 
     </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> 
    </dict> 
</dict> 

這是plist與僅NSAppTransportSecurity密鑰值的部分。請嘗試一次並確認發生了什麼。

也請按照AppDelegate.m中的代碼進行操作。請設置您的AppDelegate.m如下

#import "AppDelegate.h" 
#import <FBSDKCoreKit/FBSDKCoreKit.h> 



@implementation AppDelegate 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 


[[FBSDKApplicationDelegate sharedInstance] application:application 
         didFinishLaunchingWithOptions:launchOptions]; 
    return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application { 

} 

- (void)applicationDidEnterBackground:(UIApplication *)application { 

} 

- (void)applicationWillEnterForeground:(UIApplication *)application { 

} 

- (void)applicationDidBecomeActive:(UIApplication *)application { 

    [FBSDKAppEvents activateApp]; 
} 

    //This is very important for callback 

- (BOOL)application:(UIApplication *)application 
     openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
    annotation:(id)annotation { 


      return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; 
     } 

    } 

@end 

請嘗試所有這些和評論發生了什麼,使我們可以幫助你。

+0

所以我修好了。我在AppDelegate中犯了一個錯誤,但我不確定是什麼原因造成了一個複製並粘貼了我之前的一個項目。我會在一分鐘後解決它,併發布我改變的內容。 – user2581628

相關問題