首页 文章

如何获得Corona Simulator正在使用的操作系统?

提问于
浏览
0

我只想知道是否有任何方法可以获得运行Corona模拟器的主机操作系统?

我知道 system.getInfo("environment") == "simulator"system.getInfo("platform") .

在Corona Simulator中,返回的值取决于所选的外观,允许您通过更改外观来测试与平台相关的逻辑 .

我在Windows上开发,我的模拟器皮肤设置为Android设备但是 system.getInfo("platform") 我找不到主机操作系统(即Windows) .

1 回答

  • -1

    我错过了关于你想知道模拟器是否在Windows,macOS或其他系统上运行的观点 . 显然,正如你所说,这将使你成为皮肤的平台 .

    system.getInfo()API允许您获取平台:

    http://docs.coronalabs.com/api/library/system/getInfo.html#platform

    如果您使用“android”,“ios”,“win32”等,这将告诉您 .

    只有少数用例你会关心运行模拟器的是什么 . 在大多数情况下,您希望模拟最终设备 . 我猜你正在构建一个用户将在Windows或macOS上运行的工具 . 我认为你会为Windows或macOS二进制文件构建一个.exe文件并将其分发给任何想要使用它的人 .

    但是您可以使用“architectureInfo”来获取底层架构信息 . 如果你在Windows上,它将返回类似“x86”或“x64”的内容 . 你可以测试它,看看你是否在模拟器中运行:

    if system.getInfo( "environment" ) == "simulator" then
        if (system.getInfo("architectureInfo") == "x86" or system.getInfo("architectureInfo") == "x64") then
            print("This simulator is running on Windows")
        elseif (system.getInfo("architectureInfo") == "x86_64" or system.getInfo("architectureInfo") == "i386") then
            print("This simulator is running on macOS")
        end
    end
    

    见:http://docs.coronalabs.com/api/library/system/getInfo.html#architectureinfo

相关问题