简体   繁体   English

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

[英]How to integrate Facebook without redirect Safari browser in iOS app with latest FBSDK

Hi i am search the answer for avoid new facebooksdk redirect to safari.how to open facebook login view inside the app.if it redirect to safari may reject in app store?嗨,我正在搜索避免新 facebooksdk 重定向到 safari 的答案。如何在应用程序内打开 facebook 登录视图。如果重定向到 safari 可能会在应用程序商店中拒绝? help me.. thanks in advance帮助我.. 提前致谢

yesterday I submit my app to store using FBSDKLoginManager using three kinds of Login with Facebook , actually Facebook follow the first three conditions automatically昨天我使用FBSDKLoginManager使用三种 Login with Facebook 将我的应用程序提交到商店,实际上 Facebook 会自动遵循前三个条件

Type -1类型-1

if the user already installed the Facebook native app the details will be retrieved from the app.如果用户已经安装了 Facebook 原生应用,则将从应用中检索详细信息。

Type -2类型-2

if the user does't have the Facebook app, but he is logged in at the device's Settings, the user details will be taken from those.如果用户没有 Facebook 应用程序,但他已在设备的设置中登录,则将从这些应用程序中获取用户详细信息。

Type -3类型-3

if none of the condition above is satisfied the user will be automatically redirected to Safari .如果以上条件都不满足,用户将被自动重定向到Safari

Type -4类型-4

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

apple does not reject your app苹果不会拒绝你的应用

Objective-C目标-C

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

Swift迅速

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

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

the new concept新概念

Facebook SDK for iOSv4.x 适用于 iOSv4.x 的 Facebook SDK

(v4.6.0 - September 10, 2015) In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari. (v4.6.0 - 2015 年 9 月 10 日)此外,诸如 Login、Like、Share Dialogs 等 SDK 对话框会根据设备自动确定最佳 UI,包括 SFSafariViewController 而不是 Safari。 Follow the our Preparing for iOS 9 guide.按照我们的 iOS 9 准备指南进行操作。

you can get like你可以像

enter image description here

When your select login behavior is FBSDKLoginBehaviorWeb , Then open webView popUp.当您选择的登录行为是FBSDKLoginBehaviorWeb ,然后打开 webView 弹出窗口。

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

PopUp Facebook :弹出式脸书:

在此处输入图片说明

Note : when facebook behavior is FBSDKLoginBehaviorBrowser then its always redirect on safari browser.注意:当 facebook 行为是FBSDKLoginBehaviorBrowser它总是在 safari 浏览器上重定向。 Change its behavior to FBSDKLoginBehaviorWeb .将其行为更改为FBSDKLoginBehaviorWeb

Use This For Latest Update from FB SDK将此用于 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];
        }
    }];

In swift When your select login behavior is Web, Then open webView popUp.在 swift 当您选择的登录行为是 Web 时,然后打开 webView 弹出窗口。

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

        fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web

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

Here i use the code like:在这里我使用如下代码:

AppDelegate.swift 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登录ViewController.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)
            }
        })
    }
}

But what if I am not using FBSDKLoginManager ...?但是如果我不使用FBSDKLoginManager怎么FBSDKLoginManager ...?

But what if I do not implement a Facebook login method in my ViewController and I am just using the FBSDKLoginButton Facebook SDK touch upside action outlet implementation to login, which by default uses the Safari browser?但是如果我没有在我的 ViewController 中实现 Facebook 登录方法并且我只是使用FBSDKLoginButton Facebook SDK touch FBSDKLoginButton action outlet 实现来登录,默认情况下使用 Safari 浏览器怎么办?

How do I change the FBSDKLoginBehavior ?如何更改FBSDKLoginBehavior

If you are using the FBSDKLoginButton without your own Touch Up Inside action outlet, aka, you just added a UIButton or UIView to your Storyboard and changed its type to FBSDKLoginButton and that was enough, when the UI Component was touched to get Safari Facebook Authentication working...如果您使用的FBSDKLoginButton没有自己的 Touch Up Inside 操作插座,也就是,您只需将 UIButton 或 UIView 添加到您的故事板并将其类型更改为FBSDKLoginButton就足够了,当触摸 UI 组件以使 Safari Facebook 身份验证工作时...

To change FBSDKLoginBehavior simply add an Outlet in your ViewController to your Storyboard FBSDKLoginButton and set loginBehavior , no need to use FBSDKLoginManager :要更改FBSDKLoginBehavior只需在您的 ViewController 中添加一个 Outlet 到您的 Storyboard FBSDKLoginButton并设置loginBehavior ,无需使用FBSDKLoginManager

@IBOutlet weak var btnFbSignIn: FBSDKLoginButton!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何整合Facebook / Google +而无需在iOS应用中重定向Safari浏览器 - How to integrate Facebook/Google+ without redirect Safari browser in iOS app facebook iOS SDK授权,无需重定向到safari - facebook iOS SDK authorization without redirect to safari 如何在iOS的FBSDK中标记Facebook页面 - How to tag a facebook page in FBSDK for iOS 如何将我的应用程序集成到 ios 中的“Facebook”应用程序中? - how to integrate my app into `Facebook` app in ios? 将应用程序与本机Facebook iOS集成,而无需使用iOS应用程序 - integrate app with native facebook iOS without using an iOS app iOS FBSDK上的Facebook登录 - Facebook login on iOS FBSDK 如何制作在Safari中为iOS Facebook Messenger Messenger应用而不是应用内网络浏览器打开的URL - How to make url that open in Safari for iOS Facebook Messenger app instead of in-app web browser 网站无法在iOS版Facebook App中打开,也无法重定向到Safari - Site won't open in Facebook App for ios, nor redirect to Safari iOS Facebook最新的SDK无法通过本机应用程序登录,但可以通过浏览器登录 - iOS Facebook latest SDK cannot login through native App but browser 如何在 fbsdk 登录 React Native 中更改名称应用程序('项目想要使用 facebook.com')iOS - How to change name App in fbsdk login React Native ('Project wants to Use facebook.com') iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM