2012-06-07 33 views

回答

11

沒有編譯器指令(條件編譯符號)來確定您是在iPhone模擬器還是在設備上運行。

但是,您可以判斷它在運行時,使用此代碼:

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

這就是從這裏開始:http://docs.xamarin.com/ios/recipes/General/Projects/Environment_Checks

+2

如果需要,你可以在編譯器選項上添加自己的編譯時間符號每個項目設置 – Stuart

+0

現在是在Xamarin.iOS:'靜態布爾InSimulator() \t \t { \t \t \t回ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR; \t \t} https://developer.xamarin.com/api/type/ObjCRuntime.Arch/ –

+0

@BenButzer:謝謝,我也更新了答案。 –