2011-02-04 2 views
5

Sto lavorando su PhoneGap e ho un FBConnect. Utilizzando childBrowser e il blog'http: //www.pushittolive.com/post/1239874936/facebook-login-on-iphone-phonegap ', ho effettuato l'accesso all'app. Ma non è stato possibile disconnettersi dall'app. Viene autofirmato ogni volta che accedo.Logout da Facebook utilizzando childBrowser e PhoneGap in IPhone

Qualcuno può dirmi come uscire da FBConnect utilizzando Childbrowsern PhoneGap?

risposta

9

Prova questo.

Aggiungi questa funzione per ChildBrowserCommand.m

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

Aggiungi questo al Childbrowser.js

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

Aggiungi questo al FBConnect.js

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

A vostra pagina di aggiungere questo codice per disconnettere il pulsante su clic

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

Divertiti.

+0

Stavo usando questo metodo perché sembrava funzionare, ma ora ho capito che funziona solo mentre l'app è in esecuzione. Una volta terminata e riaperta l'app, i cookie "riappariranno". C'è un modo per cancellare davvero i cookie per sempre? –

+0

Soluzione molto bella. Assicurati di includere tutte le parentesi di chiusura} su ciascuna delle funzioni sopra. Grazie! –

+0

grazie Mohamed – Henry

4

Il modo migliore per dire a Facebook di uscire.

può essere fatto con l'apertura al di sotto URL nel navigatore bambino:

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

questo mi reindirizza alla home page di facebook. non si disconnette –

0

ho lottato con questo problema per le età. È possibile che tu abbia effettuato l'accesso a Facebook, ma potresti non disporre del token di accesso in modo che il logot convenzionale non funzioni.

A proposito, ecco come forzare il logout di Facebook senza accedere al token.

<!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>