如何确定应用程序是作为移动应用程序还是桌面应用程序运行?

发布于 2024-12-19 23:22:56 字数 237 浏览 1 评论 0原文

我怎样才能知道当前的应用程序类型是什么?即它是在移动设备上运行还是作为桌面 Air 应用程序运行?

我已经尝试过:

if(FlexGlobals.topLevelApplicatoin as WindowedApplication)
 //desktop

但是移动版本找不到 WindowedApplication 类。

我如何区分?

How can I find out what the current application type is? i.e. whether it's running on a mobile device or as a desktop Air application?

I've tried this:

if(FlexGlobals.topLevelApplicatoin as WindowedApplication)
 //desktop

However the mobile Version can't find the WindowedApplication class.

How do I tell the difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

黒涩兲箜 2024-12-26 23:22:56

好的,这有效:

public static function isAndroid():Boolean
{
    return (Capabilities.version.substr(0,3) == "AND");
}
public static function isIOS():Boolean
{
    return (Capabilities.version.substr(0,3) == "IOS");
}
 ... //is Blackberry

public static function isMobile():Boolean
{
    return (isAndroid() || isIOS()); // || isBlackberry()
}

ok this works:

public static function isAndroid():Boolean
{
    return (Capabilities.version.substr(0,3) == "AND");
}
public static function isIOS():Boolean
{
    return (Capabilities.version.substr(0,3) == "IOS");
}
 ... //is Blackberry

public static function isMobile():Boolean
{
    return (isAndroid() || isIOS()); // || isBlackberry()
}
小梨窩很甜 2024-12-26 23:22:56

您可以使用 Capability.OS;但是请注意文档中的警告:

不要使用 Capability.os 或 Capability.manufacturer 来确定
基于操作系统的能力。能力基于
操作系统是一个坏主意,因为如果
应用程序不考虑所有潜在的目标操作系统。
相反,使用与该功能相对应的属性
您正在测试。

You can use Capabilities.OS; however heed this warning from the docs:

Do not use Capabilities.os or Capabilities.manufacturer to determine a
capability based on the operating system. Basing a capability on the
operating system is a bad idea, since it can lead to problems if an
application does not consider all potential target operating systems.
Instead, use the property corresponding to the capability for which
you are testing.

为你拒绝所有暧昧 2024-12-26 23:22:56

这是我用来确定它是哪个操作系统以及是否是移动操作系统的类,当然这仅涵盖 Windows、Linux Android 和 iOS:

package com.fw3dlogical.utils {

    import flash.system.Capabilities;

    /**
     * Platform
     * @author Juan Fernando Velez
     */
    public class Platform {

            public static function get isWin():Boolean {
                return (Capabilities.version.indexOf("WIN") != -1);
            }

            public static function get isLinux():Boolean {
                return (Capabilities.version.indexOf("LNX") != -1);
            }

            public static function get isAndroid():Boolean {
                return (Capabilities.version.indexOf("AND") != -1);
            }

            public static function get isiOS():Boolean {
                return (Capabilities.version.indexOf("IOS") != -1);
            }

            public static function isMobile():Boolean {
                return (isAndroid() || isiOS());
            }

        }
    }
}

This is the class I use for determine which os is it and if it's Mobile or not, of course this only covers Windows, Linux Android and iOS:

package com.fw3dlogical.utils {

    import flash.system.Capabilities;

    /**
     * Platform
     * @author Juan Fernando Velez
     */
    public class Platform {

            public static function get isWin():Boolean {
                return (Capabilities.version.indexOf("WIN") != -1);
            }

            public static function get isLinux():Boolean {
                return (Capabilities.version.indexOf("LNX") != -1);
            }

            public static function get isAndroid():Boolean {
                return (Capabilities.version.indexOf("AND") != -1);
            }

            public static function get isiOS():Boolean {
                return (Capabilities.version.indexOf("IOS") != -1);
            }

            public static function isMobile():Boolean {
                return (isAndroid() || isiOS());
            }

        }
    }
}
合约呢 2024-12-26 23:22:56

如果您需要知道您是在移动设备还是桌面设备上运行,您应该检查Capability.cpuArchitecture:

if(Capabilities.cpuArchitecture=="ARM")
{
  
}

If you need to know whether you are running on mobile or desktop you should check for Capabilities.cpuArchitecture:

if(Capabilities.cpuArchitecture=="ARM")
{
  
}
独夜无伴 2024-12-26 23:22:56

我不知道,
但我们无法将 FlexGlobals.topLevelApplicatinn 转换为 Mobile Application 中的 WindowedApplication。

因此,移动应用程序可以来自以下类型:

1.TabbedViewNavigatorApplication - 用于选项卡式视图导航应用程序

2.viewnavigatorapplication - 基于视图的导航应用程序

因此,作为您的应用程序类型,您应该尝试从上述两个选项进行转换......

I'm not sure,
But we can not convert FlexGlobals.topLevelApplicatinn into WindowedApplication in Mobile Application.

So, Mobile Applications can be from the following types:

1.TabbedViewNavigatorApplication - for Tabbed View Navigation Application

2.viewnavigatorapplication - view based navigation application

So as your application type you should try from above two options for conversion....

笛声青案梦长安 2024-12-26 23:22:56

此测试将在移动应用程序中进行,无需测试特定操作系统名称(例如 Capability.os 或 Capability.version)。它的优点是在桌面上调试移动应用程序时能够始终如一地工作,而 Capability.os 可能无法为您提供所需的答案:

import flash.utils.getDefinitionByName;
...

var hasWindowedApp:Boolean = false;
try
{
    hasWindowedApp = getDefinitionByName("spark.components.WindowedApplication") != null;
}
catch (error:ReferenceError)
{
}

if (!hasWindowedApp)
{
    try
    {
        hasWindowedApp = getDefinitionByName("mx.core.WindowedApplication") != null;
    }
    catch (error:ReferenceError)
    {
    }
}

This test will work from a mobile app without needing to test for specific OS names (like Capabilities.os or Capabilities.version). It has the advantage of working consistently when debugging a mobile app on the desktop as well where Capabilities.os may not give you the answer you want:

import flash.utils.getDefinitionByName;
...

var hasWindowedApp:Boolean = false;
try
{
    hasWindowedApp = getDefinitionByName("spark.components.WindowedApplication") != null;
}
catch (error:ReferenceError)
{
}

if (!hasWindowedApp)
{
    try
    {
        hasWindowedApp = getDefinitionByName("mx.core.WindowedApplication") != null;
    }
    catch (error:ReferenceError)
    {
    }
}
风吹过旳痕迹 2024-12-26 23:22:56

C# 函数检查 IOS(iPad, iPhone)

    public bool isIOS()
    {
        HttpContext context = HttpContext.Current;

        if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
        {
            foreach (string s in new[] { "iPad", "iphone" })
            {
                if (context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
                {
                    return true;
                }
            }
        }

        return false;
    }

C# Function to check IOS(iPad, iPhone)

    public bool isIOS()
    {
        HttpContext context = HttpContext.Current;

        if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
        {
            foreach (string s in new[] { "iPad", "iphone" })
            {
                if (context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower()))
                {
                    return true;
                }
            }
        }

        return false;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文