2011-02-04 50 views
5

我正在使用PhoneGap並擁有FBConnect。使用childBrowser和blog'http://www.pushittolive.com/post/1239874936/facebook-login-on-iphone-phonegap',我已登錄到應用程序。但無法從應用程序註銷。每次登錄時都會自動登錄。使用iPhone中的childBrowser和PhoneGap從Facebook登出來

任何人可以告訴我如何使用Childbrowsern PhoneGap從FBConnect註銷?

回答

9

試試這個。

添加此功能ChildBrowserCommand.m

-(void) deleteCookies:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{ 
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
    for (NSHTTPCookie *each in [cookieStorage cookies]) { 
      [cookieStorage deleteCookie:each]; 
    } 
} 

一下添加到Childbrowser.js

ChildBrowser.prototype.LogOut = function() 
{ 
    PhoneGap.exec("ChildBrowserCommand.deleteCookies"); 
} 

這FBConnect.js

FBConnect.prototype.Logout = function() 
{ 
    window.plugins.childBrowser.LogOut();  
} 

添加在您的網頁添加此代碼點擊註銷按鈕

function Logout() 
{ 
    var fb=FBConnect.install(); 
    fb.Logout(); 
} 

享受。

+0

我正在使用這種方法,因爲它似乎工作,但現在我意識到,它只適用於應用程序運行。一旦你終止並重新打開應用程序,cookies將「重新出現」。 有什麼辦法可以真正刪除cookies嗎? – 2011-05-20 22:37:47

+0

非常好的解決方案。確保在上述每個函數中包含所有右括號}。謝謝! – 2011-09-01 06:10:49

4

告知Facebook註銷的最佳方式。

它可以通過兒童瀏覽器中打開以下網址進行:

"https://www.facebook.com/logout.php?next="+your_site_url_registered _on_fb+"&access_token="+accessToken 
0

我有這個問題的年齡掙扎。您可能在Facebook上登錄,但您可能沒有訪問令牌,因此傳統的登錄無法使用。

順便說一下,這裏是如何強制沒有訪問令牌的Facebook註銷。

<!DOCTYPE html> 
<html xmlns:fb="https://www.facebook.com/2008/fbml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Force facebook logout without access token</title> 
</head> 
<body> 
    <h3>Please wait while we redirect kick you out from Facebook...</h3> 
    <div id="status"></div> 
    <div id="fb-root"></div> 
    <script type="text/javascript"> 
     function spitInfo(message) { 
      var infoDiv = document.getElementById("status"); 
      infoDiv.innerHTML += message; 
      infoDiv.innerHTML += "<br/>"; 
     } 

     window.fbAsyncInit = function() { 
      spitInfo("called asyncInit"); 

      FB.init({ 
       appId: '496676837086475', //change the appId to your appId 
       status: true, 
       cookie: true, 
       xfbml: true, 
       oauth: true 
      }); 


      function forceLogOut(response) { 
       if (response.authResponse) { 

        FB.logout(function (response) { 
         spitInfo("FB.logout caller - you are logged out"); 
        }); 
       } else { 
        spitInfo("Already logged out"); 
       } 
      } 

      // run once with current status and whenever the status changes 
      FB.getLoginStatus(forceLogOut); 
      FB.Event.subscribe('auth.statusChange', forceLogOut); 
     }; 
     (function() { 
      var e = document.createElement('script'); 
      e.async = true; 
      e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
      document.getElementById('fb-root').appendChild(e); 
     }()); 
    </script> 
</body> 
</html> 
相關問題