iOS Swift判断代码运行在模拟器上

来源:互联网 发布:sql查询有的时间慢 编辑:程序博客网 时间:2024/05/21 21:46

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

1 0
原创粉丝点击