MonoTouch编译器针对iPhone模拟器的指令

8

有没有人知道我在使用MonoTouch时应该使用哪个编译指令来查看我是否在iPhone模拟器上运行?无法在任何地方找到相关信息。

谢谢!

1个回答

12

在编译器中没有指令(条件编译符号)可以确定您是在iPhone模拟器上运行还是在设备上运行。

但是您可以在运行时使用以下代码来确定:

using ObjCRuntime;
static bool InSimulator ()
{
    return Runtime.Arch == Arch.SIMULATOR;
}

这段内容来源于这里:http://docs.xamarin.com/ios/recipes/General/Projects/Environment_Checks


2
如果需要的话,您可以在每个项目设置的编译器选项中添加自己的编译时符号。 - Stuart
现在它在Xamarin.iOS中:static bool InSimulator () { return ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR; }https://developer.xamarin.com/api/type/ObjCRuntime.Arch/ - Ben Butzer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接