如何在不使用最新的FBSDK在iOS应用程序中重定向Safari浏览器的情况下集成Facebook

时间:2015-07-09 07:43:36

标签: ios objective-c iphone facebook

您好我正在搜索答案,以避免新的facebooksdk重定向到safari.how在app内打开Facebook登录视图。如果它重定向到safari可能会拒绝在应用程序商店?帮帮我..提前谢谢

6 个答案:

答案 0 :(得分:17)

昨天我使用FBSDKLoginManager使用三种登录方式将我的应用程序提交到商店,实际上Facebook会自动遵循前三个条件

输入-1

如果用户已安装Facebook本机应用程序,则将从应用程序中检索详细信息。

输入-2

如果用户没有Facebook应用,但他已在设备的设置中登录,则会从这些用户详细信息中获取用户详细信息。

键入-3

如果上述条件均不满足,则用户将自动重定向至Safari

键入-4

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

apple不会拒绝您的应用

<强>目标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

FBSDKLoginBehavior类型

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,
   };

新概念

Facebook SDK for iOSv4.x

  

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

你可以得到像

enter image description here

答案 1 :(得分:8)

当您的选择登录行为为" 时,请打开webView popUp。

FBSDKLoginBehaviorWeb

PopUp Facebook:

enter image description here

注意:当Facebook行为为FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior=FBSDKLoginBehaviorWeb; 时,它始终会在Safari浏览器上重定向。将其行为更改为FBSDKLoginBehaviorBrowser

将此用于FB SDK的最新更新

FBSDKLoginBehaviorWeb

答案 2 :(得分:3)

迅速 当您选择登录行为是Web时,请打开webView popUp。

 // Try to login with permissions
        let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()

        fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web

答案 3 :(得分:2)

只需打开Facebook开发者网站http://facebookdevelopers.com 在那里,您将获得整个过程,将Facebook集成到您的应用程序中,而无需重定向到Safari浏览器。

答案 4 :(得分:1)

这里我使用的代码如下:

<强> 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)
            }
        })
    }
}

答案 5 :(得分:0)

但是,如果我没有使用FBSDKLoginManager ...

,该怎么办?

但是,如果我没有在我的ViewController中实现Facebook登录方法,我只是使用FBSDKLoginButton Facebook SDK触摸上行动作插件实现登录,默认使用Safari浏览器?

如何更改FBSDKLoginBehavior

如果您使用FBSDKLoginButton而没有自己的Touch Up Inside动作插座,也就是说,您刚刚在故事板中添加了UIButton或UIView,并将其类型更改为FBSDKLoginButton,这就足够了,感兴趣的UI组件让Safari Facebook身份验证工作......

要更改FBSDKLoginBehavior,只需将ViewController中的Outlet添加到故事板FBSDKLoginButton并设置loginBehavior,无需使用FBSDKLoginManager

@IBOutlet weak var btnFbSignIn: FBSDKLoginButton!

override func viewDidLoad() {
    btnFbSignIn.loginBehavior = FBSDKLoginBehavior.web
}