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://blog.csdn.net/offbye/article/details/50686407