2012-05-07 56 views
1

按下facebook按鈕後,用戶登錄,然後webview立即轉到facebook移動站點。我需要的是該webview消失,因此我可以繼續與我的應用進行交互,而不是與facebook移動網站進行交互。如何在登錄後刪除facebookWebView? Flash Builder 4.6 ios開發

我很抱歉,如果我不清楚,上午5點和我,在這裏有點瘋狂大聲笑。看看代碼...

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    backgroundColor="#2F28C1" title="Setup" 
    creationComplete="application1_creationCompleteHandler(event)"> 
<fx:Script> 
    <![CDATA[ 
     import com.facebook.graph.FacebookMobile; 

     import mx.events.FlexEvent; 

     import views.setup_first.facebook; 
     import views.setup_first.flickr; 
     import views.setup_first.google; 
     import views.setup_first.tumblr; 
     import views.setup_first.twitter; 

     public var permissions:Array = ["user_birthday", "read_stream", "publish_stream"]; 

     protected function application1_creationCompleteHandler(event:FlexEvent):void 
     { 
      FacebookMobile.init("262320357178421", loginHandler); 

     } 

     protected function loginHandler(success:Object,fail:Object):void 
     { 


     } 

     protected function login():void 
     { 
      var facebookWebView:StageWebView = new StageWebView(); 
      facebookWebView.viewPort = new Rectangle (0,0, stage.width, stage.height); 
      FacebookMobile.login(loginHandler, this.stage, permissions, facebookWebView); 
      trace("I'm logged in!"); 

     } 

     protected function logout():void 
     { 
      FacebookMobile.logout(onLogout, "https://m.facebook.com/dialog/permissions.request?app_id=262320357178421&display=touch&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&type=user_agent&perms=publish_stream&fbconnect=1"); 

     } 

     protected function onLogout(result:Object):void 
     { 
      trace("Perfect Log Out!") 
     } 


    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 

<s:navigationContent/> 

<s:Button left="62" top="86" click="navigator.pushView(views.setup_first.google)" 
      icon="@Embed('../Setup/Setup_0002_Layer-5.png')"/> 

<s:Button right="64" top="86" click="login()" icon="@Embed('../Setup/Setup_0001_Layer-6.png')"/> 

<s:Button click="navigator.pushView(views.setup_first.tumblr)" horizontalCenter="-4" 
      icon="@Embed('../Setup/Setup_0000_Layer-7.png')" verticalCenter="-14"/> 

<s:Button left="62" bottom="117" click="navigator.pushView(views.setup_first.flickr)" 
      icon="@Embed('../Setup/Setup_0004_Setup.png')"/> 

<s:Button right="63" bottom="117" click="navigator.pushView(views.setup_first.twitter)" 
      icon="@Embed('../Setup/Setup_0005_Layer-1.png')"/> 

<s:Button right="54" bottom="10" label="Skip" click="navigator.pushView(thirdPage)"/> 
<s:Button id="logOut" x="323" y="210" height="28" label="LogOut" fontSize="15" 
      click="logout()"/> 

回答

0

你好科裏,我不知道,如果你解決你的問題,但我確實只是一個時刻,所以我會告訴你我的經驗。

如果用戶登錄並將應用程序安裝到他的facebook應用程序中,loginHandler將與FacebookSession一起成功分派,並且facebookWebView將自動刪除。 但是,如果用戶取消安裝或不允許請求的權限,則不會發送任何事件,並且facebookWebView會顯示一個帶有「成功」一詞的白頁。 我已經修復了將位置變化事件的facebookWebView添加到監聽器的問題。然後總是通過facebookWebView更改顯示該方法的url,包括何時發生用戶拒絕錯誤(當用戶不允許該應用程序時調度)。 這是我的代碼:

private var facebookWebView:StageWebView = new StageWebView(); 

protected function login():void{ 
    facebookWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChange); 
    facebookWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChange); 
    facebookWebView.viewPort = new Rectangle(0, 0, stage.width, stage.height); 
    FacebookMobile.login(onLogin, this.stage, permissions, facebookWebView); 
} 

private function locationChange(e:LocationChangeEvent):void 
{ 
    var url:String = e.location; 
    if(url.search("error") != -1) 
     removeFacebookView(); 
} 

protected function onLogin(success:Object, fail:Object):void{ 
    if(success){ 
     //save user content FacebookSession(success).user 
     removeFacebookView(); 
     setCurrentState("login"); 
    } 
} 

private function removeFacebookView():void 
{ 
    facebookWebView.removeEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChange); 
    facebookWebView.removeEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChange); 
    this.actionBarVisible = true; 
    facebookWebView.stage = null; 
} 

正如你可以看到刪除facebookWebView我在視圖中的變量,而不是函數的局部變量。 (你也可以用e.target來獲得它)。你會用facebookWebView.stage = null刪除它;不要刪除eventlistener之前。只有當loginhandle成功發送,並且出現錯誤時您必須刪除facebookWebView。