简体   繁体   English

检测iOS模拟器与iOS设备

[英]Detect iOS Simulator vs. iOS Device

I am working on a project using Xamarin.iOS and I have a situation where a behavior in the simulator inexplicably is not the same on an actual device (setting the region of a mapview centers differently). 我正在使用Xamarin.iOS进行一个项目,我有一种情况,模拟器中的行为莫名其妙地在实际设备上不一样(设置mapview中心区域的方式不同)。

I want to be able to set a value for a variable at runtime based on whether the app is running on the simulator or a real device. 我希望能够根据应用程序是在模拟器上还是在真实设备上运行,在运行时为变量设置值。 How can I detect this? 我怎么能发现这个?

You can execute different code at runtime like this: 您可以在运行时执行不同的代码,如下所示:

if (ObjCRuntime.Runtime.Arch == Arch.DEVICE) {
} else {
}

But it's always good to investigate (ask around here, forums, bug reports) why the behaviour differs between the two (just to make sure it does not hide a bug that could bite you later). 但是调查(在这里询问,论坛,错误报告)为什么两者之间的行为不同(这只是为了确保它不会隐藏可能会在以后咬你的错误)总是好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM