1

按下 facebook 按钮后,用户登录,然后该 web 视图立即转到 facebook 移动站点。我需要的是让那个 webview 消失,这样我就可以继续与我的应用程序交互,而不是 facebook 移动网站。

如果我不清楚,我很抱歉,现在是凌晨 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()"/>

4

1 回答 1

0

你好科里我不知道你是否解决了你的问题,但我只是做了一会儿,所以我会告诉你我的经历。

使用您的代码,如果用户登录并在他的 facebook 应用程序中安装应用程序,loginHandler 将与 FacebookSession 一起成功调度,并且 facebookWebView 会自动删除。但是,如果用户取消安装或不允许请求的权限,则不会发送任何事件,并且 facebookWebView 会显示一个带有“成功”字样的白页。我已经修复了将侦听器添加到位置 chage 事件的 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; 删除它 之前不要删除事件监听器。仅当 loginhandle 成功发送,并且出现错误且您必须删除 facebookWebView 时。

于 2012-05-29T10:50:54.227 回答