iOS模拟器有些功能没有,比如拍照,因此代码中需要加个模拟器判断,查了好多文章,终于找到了。swift代码如下:
struct Platform {
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
#endif
return isSim
}()
}
// Elsewhere...
if Platform.isSimulator {
// Do one thing
}
else {
// Do the other
}
参考 http://themainthread.com/blog/2015/06/simulator-check-in-swift.html

本文提供了一段Swift代码用于在iOS应用中判断设备是否为模拟器,并处理拍照功能在模拟器中不可用的问题。通过检查架构信息,代码能够准确识别模拟器环境,从而避免在模拟器上运行不兼容的功能。
896

被折叠的 条评论
为什么被折叠?



