简体   繁体   English

如何防止iOS中的本机Facebook登录对话框?

[英]how can I prevent native facebook login dialog in ios?

I am using facebooksdk.framework 3.1 我正在使用facebooksdk.framework 3.1

when I login my app with my account, native login dialog pops up even though web based auth 当我使用我的帐户登录我的应用程序时,即使基于Web的身份验证也会弹出本机登录对话框
completed. 完成。 I need to turn off either native login dialog or web based auth but I don't know how. 我需要关闭本机登录对话框或基于Web的身份验证,但我不知道如何。

I tried to find facebook.m file but there was no such file on facebooksdk.framework 3.1 我试图找到facebook.m文件,但是facebooksdk.framework 3.1上没有这样的文件

how do I turn off safariauth or native auth?? 如何关闭safariauth或本机身份验证? It is very strange two login process occurs at the same time. 很奇怪,两个登录过程同时发生。

First of all go to facebook.m page & try to find the following method: 首先转到facebook.m页面并尝试找到以下方法:

- (void)authorize:(NSArray *)permissions
         delegate:(id<FBSessionDelegate>)delegate
       localAppId:(NSString *)localAppId 

in this method there is a line: [self authorizeWithFBAppAuth:YES safariAuth:NO]; 在此方法中,有一行: [self authorizeWithFBAppAuth:YES safariAuth:NO];

change authorizeWithFBAppAuth & safariAuth to yes/no according to your need.Hope it helps you. 根据您的需要将authorizeWithFBAppAuth和safariAuth更改为是/否。希望它对您有所帮助。

Or you can try to implement latest Share kit sdk.it is best way. 或者您可以尝试实施最新的Share kit sdk。这是最好的方法。

If you use phonegap facebook plugin, you should call FB.getLoginStatus() carefully. 如果您使用phonegap facebook插件,则应仔细调用FB.getLoginStatus()。

If FB.getLoginStatus() fires before FB.init() is done, the function would return a response as 如果在FB.init()完成之前触发FB.getLoginStatus(),则该函数将返回以下响应:

'not connected' even if user is already connected. 即使用户已经连接,也“未连接”。

my login problem was due to FB.getLoginStatus() on my redirected page. 我的登录问题是由于重定向页面上的FB.getLoginStatus()引起的。

even if user succed login and procceded to my redirected page, the page run FB.getLoginStatus() 即使用户成功登录并访问了我的重定向页面,该页面也会运行FB.getLoginStatus()

and result was always 'not connected' because FB.init() not completely executed. 结果总是“未连接”,因为FB.init()未完全执行。

facebook provides async function to solve this problem but it didn't work when I tested on phonegap. facebook提供了异步功能来解决此问题,但是当我在phonegap上进行测试时它无法正常工作。

to check user login, I use FB.Event.subscribe and localstorage for now. 要检查用户登录,我现在使用FB.Event.subscribe和localstorage。

on the page that needs FB functions, I added this javascript code 在需要FB功能的页面上,我添加了此javascript代码

FB.Event.subscribe('auth.login', function(response){
    localStorage.setItem('fblogin', true);
    console.log('login event');
}
FB.Event.subscribe('auth.logout', function(response){
    localStorage.setItem('fblogin', false);
    console.log('logout event');
}

document.addEventListener('deviceready', function(){
 try{
      FB.init({ appId : '1234567889' , nativeInterface : CDV.FB, useCachedDialogs : true});
 }catch(e){
      alert(e);
 }
 var fbval = localStorage.getItem('fblogin');
 if(fbval){
     // your code for connected status
 }
}); 

basically, I set 'fblogin' localStorage value true whenever login event occurs, 基本上,每当发生登录事件时,我都将'fblogin'localStorage值设置为true,
and set the value 'false' whenever logout event occurs. 并在发生注销事件时将值设置为“ false”。
by comparing 'fblogin' value, I check users are logged or not. 通过比较“ fblogin”值,我检查用户是否已登录。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM