如何在不使用redirectSafari浏览器的情况下将iOS应用程序与最新的FBSDK进行整合

您好,我search的答案,以避免新的Facebook的Facebookredirectsafari.how打开Facebook的应用程序内的login视图,如果redirect到Safari可能拒绝在应用程序商店? 帮助我..提前感谢

昨天我提交我的应用程序使用FBSDKLoginManager使用三种login与Facebook存储,实际上Facebook自动遵循前三个条件

键入-1

如果用户已经安装了Facebook本地应用程序的细节将被从应用程序中检索。

types-2

如果用户没有Facebook应用程序,但他已经在设备的设置中login,则用户的详细信息将从这些设备中获取。

types-3

如果以上条件都不满足,用户将被自动redirect到Safari

types-4

  if you none of the above three conditions is relevant for you please continue below code. 

苹果不会拒绝你的应用程序

Objective-C的

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior=FBSDKLoginBehaviorWeb; // it open inside the app using popup menu 

迅速

 var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.loginBehavior = FBSDKLoginBehavior.Native 

FBSDKLoginBehaviortypes

 typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior) { /*! @abstract Attempts log in through the native Facebook app. If the Facebook app is not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the default behavior. */ FBSDKLoginBehaviorNative = 0, /*! @abstract Attempts log in through the Safari browser */ FBSDKLoginBehaviorBrowser, /*! @abstract Attempts log in through the Facebook account currently signed in through Settings. If no Facebook account is signed in, falls back to \c FBSDKLoginBehaviorNative. */ FBSDKLoginBehaviorSystemAccount, /*! @abstract Attemps log in through a modal \c UIWebView pop up @note This behavior is only available to certain types of apps. Please check the Facebook Platform Policy to verify your app meets the restrictions. */ FBSDKLoginBehaviorWeb, }; 

新的概念

适用于iOSv4.x的Facebook SDK

(v4.6.0 – 2015年9月10日)此外,诸如Login,Like,Share对话框之类的SDK对话框会自动确定基于设备的最佳UI,包括SFSafariViewController而不是Safari。 按照我们的准备iOS 9指南。

你可以得到像

enter image description here

当你select的login行为是FBSDKLoginBehaviorWeb ,然后打开webViewpopup窗口。

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior=FBSDKLoginBehaviorWeb; 

PopUp Facebook:

在这里输入图像描述

注意:当facebook的行为是FBSDKLoginBehaviorBrowser那么它总是在Safari浏览器上redirect。 将其行为更改为FBSDKLoginBehaviorWeb

使用此从FB SDK的最新更新

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior = FBSDKLoginBehaviorWeb; NSArray *userdetails; [login logInWithReadPermissions:userdetails fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { NSLog(@"Login Error : %@", error.description); } else if(result.isCancelled) { NSLog(@"Login Cancel By User"); } else { //[self fetchUserDataForFacebookLogin]; //[login logOut]; } }]; 

只需打开Facebook开发人员网站http://facebookdevelopers.com ,您将获得将Facebook整合到您的应用程序而不redirect到Safari浏览器的整个过程。

在swift中当你select的login行为是Web时,然后打开webView popUp。

  // Try to login with permissions let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web 

在这里我使用这样的代码:

AppDelegate.swift

 import UIKit import FBSDKCoreKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } func applicationWillResignActive(application: UIApplication) { FBSDKAppEvents.activateApp() } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } } 

LoginViewController.swift

  //MARK: FacebookLogin Button @IBAction func btnFacebookLoginClicked(sender: AnyObject) { let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.logOut() fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web //Without safari Browser fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in if (error != nil){ let fbloginresult : FBSDKLoginManagerLoginResult = result if(fbloginresult.grantedPermissions.contains("email")){ self.getFBUserData() fbLoginManager.logOut() } }else if result.isCancelled { print("Cancelled") } }) } func getFBUserData(){ if((FBSDKAccessToken.currentAccessToken()) != nil){ FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in if (error == nil){ self.facebookUserDict = result as! NSDictionary print(result) print(self.facebookUserDict) print(self.facebookUserDict.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as! String) } }) } } 

但是,如果我不使用FBSDKLoginManager …?

但是,如果我没有在我的ViewController中实现Facebooklogin方法,并且我只是使用FBSDKLoginButton Facebook SDK触摸向上操作sockets实现login,默认情况下使用Safari浏览器?

我如何更改FBSDKLoginBehavior

如果你使用FBSDKLoginButton而没有你自己的Touch Up Inside动作sockets, FBSDKLoginButton ,你刚刚添加了一个UIButton或者UIView到你的Storyboard,并且改变了它的types为FBSDKLoginButton ,这足够了,当触摸UI组件时, …

要更改FBSDKLoginBehavior只需在您的ViewController中添加一个Outlet到您的Storyboard FBSDKLoginButton并设置loginBehavior ,不需要使用FBSDKLoginManager

 @IBOutlet weak var btnFbSignIn: FBSDKLoginButton! override func viewDidLoad() { btnFbSignIn.loginBehavior = FBSDKLoginBehavior.web }