About

<#TEMPLATE_INCLUDE_NINEPAGE_ABOUTME#>
  • Jun

    26

    读取 iOS 屏幕物理点数完整样例代码

    • 1 Comments
    • Flash Platform
    • 发布:古树悬叶
    • 引用:0
    • 浏览:

    继续《Adobe AIR 读取屏幕物理点数(非物理尺寸、非像素尺寸)的方法》,如果不使用 StageWebViewBridge-master,这里提供一个通过 StageWebView 获取 iOS 屏幕物理点数的样例代码(如果是安卓系统,可以直接用那篇文章中引用的官方推荐值 DPI 值 160)。

    JS 部份主要代码:

    package
    {
        public class ScreenJS
        {
            public function ScreenJS()
            {
                throw Error("无法实例化的类")
            }

            //这是一个奇怪的字符串写法
            //可以参考这个贴子:http://blog.zinewow.com/post/270.html
            //这样写的目的只是为了方便字符串在AS中换行
            static public const xmlString:String =

            (<![CDATA[
                <script type="text/javascript">

                    function getInfo() 
                    {
                        var u = navigator.userAgent;


                        if(u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1)
                        {
                            window.location.href = "http://127.0.0.1/?" + window.screen.height + "x" + window.screen.width;
                        }
                    }     

                    getInfo() ;

                </script>
            ]]>);
        }
    }

    AS 部份主要代码:

    //某个地方生成了 StageWebView 对象并添加了侦听器,一般就要主函数吧
    var view:StageWebView = new StageWebView();

    view.stage = stage;
    view.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChaningHandler);
    view.loadString(ScreenJS.xmlString);


    //侦听器函数
    private function locationChaningHandler(e:LocationChangeEvent):void
    {
          e.preventDefault();//我们并不是为了跳转网页,所以这里中止跳转

          var location:String = e.location;
          var dpi:String= String(location.split("?")[1]);
          trace("dpi:", dpi);
    }
    Post Comment.
    quote 1.古树悬叶
    2015-11-9 11:23:42
    package
    {
    public class ScreenJS extends AbstractClass
    {
    public function ScreenJS()
    {
    super();
    }

    static public const xmlString:String =

    (<![CDATA[
    <script type="text/javascript">

    function getInfo()
    {
    var u = navigator.userAgent;

    if(u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1 || u.indexOf('Android') > -1)
    {
    window.location.href = "http://127.0.0.1/?" + window.screen.height;
    }
    else
    {
    window.location.href = "http://127.0.0.1/?" + 0;
    }
    }
    getInfo() ;
    </script>
    ]]>);

    }

    }

    发表评论