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 }