swift判断是否真机or模拟器


之前一直用的这种,不知道为什么不怎么靠谱

        #if TARGET_IPHONE_SIMULATOR//模拟器
            
        #else//真机
           
        #endif

  

现在用这种:

  if Platform.isSimulator {
            // Do one thing
            print("isSimulator")
        }
        else {
            jPushId = JPUSHService.registrationID()
        }



struct Platform {
    static let isSimulator: Bool = {
        var isSim = false
        #if arch(i386) || arch(x86_64)
            isSim = true
        #endif
        return isSim
    }()
}

  

 

亲测,这种可以


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM