首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用react-native-fbsdk LoginManager时如何设置LoginBehaviour?

使用react-native-fbsdk LoginManager时如何设置LoginBehaviour?
EN

Stack Overflow用户
提问于 2016-10-03 23:19:48
回答 2查看 13.7K关注 0票数 5

如果我从react-native-fbsdk使用LoginButton,LoginBehaviour似乎是“本地的”,因为SDK与安装的FB应用程序通信,看到我已经授予权限,只让我登录而不显示任何对话框,等等。

我假设我可以通过设置登录行为来改变这一点,但我不知道如何成功地做到这一点。以下是我尝试过的方法

代码语言:javascript
复制
import { GraphRequest, GraphRequestManager, LoginManager, LoginBehaviorIOS } from 'react-native-fbsdk';
LoginManager.setLoginBehavior(LoginBehaviorIOS);

//ERROR: Argument 0 (FBSDKLoginBehaviour) of FBLoginManager: must not be null

然后我试了一下:

代码语言:javascript
复制
LoginManager.setLoginBehavior('native');

// No error, but still gives me the same behaviour.

LoginButton和LoginManager在什么时候有不同的行为?如何在使用LoginManager时设置登录行为,使其像LoginButton一样工作?

我已经将所有代码添加到AppDelegate.m文件以及入门指南中包含的所有其他说明:https://developers.facebook.com/docs/ios/getting-started/

EN

回答 2

Stack Overflow用户

发布于 2017-11-13 23:27:28

我遇到了类似的问题,并设法通过如下设置登录行为来使其正常工作:

代码语言:javascript
复制
LoginManager.setLoginBehavior('NATIVE_ONLY'); 

即使在react-native-fbsdk GitHub repo中,关于这个主题的Facebook文档也很糟糕:

编辑:通过使用natie_only行为有一个捕获。用户必须在该手机上安装FB,否则FB SDK会静默失败。为了解决这个问题,我决定启动WEB_ONLY行为,以防native_only失败。我的示例是针对Android进行测试的,而不是针对iOS。

代码语言:javascript
复制
let result;
try {
  LoginManager.setLoginBehavior('NATIVE_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
} catch (error) {
  LoginManager.setLoginBehavior('WEB_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
}

EDIT :我在how to use Facebook SDK in React Native上发表了一篇文章,其中我提到了更多内容(即如何执行图形请求)。如果你需要更多关于这个主题的信息,请查看它。

票数 11
EN

Stack Overflow用户

发布于 2019-01-15 18:49:54

我也有同样的困惑。我在FBSDK源代码中找到了相关信息。Andtoid和iOS有一个不同的列表。我最终使用了跨平台版本的@jeevium answer。

代码语言:javascript
复制
// something like this
LoginManager.setLoginBehavior(Platform.OS === 'ios' ? 'native' : 'NATIVE_ONLY');

/**
 * Indicate how Facebook Login should be attempted on Android.
 */
export type LoginBehaviorAndroid =
    // Attempt login in using the Facebook App, and if that does not work fall back to web dialog auth.
    'native_with_fallback'|
    // Only attempt to login using the Facebook App.
    'native_only'|
    // Only the web dialog auth should be used.
    'web_only';

/**
 * Indicate how Facebook Login should be attempted on iOS.
 */
export type LoginBehaviorIOS =
    // Attempts log in through the native Facebook app.
    // The SDK may still use Safari instead.
    // See details in https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9/
    'native' |
    // Attempts log in through the Safari browser.
    'browser' |
    // Attempts log in through the Facebook account currently signed in through Settings.
    'system_account' |
    // Attempts log in through a modal UIWebView pop-up.
    'web';
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39835006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档