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
    }()
}

  

 

亲测,这种可以

posted @ 2016-11-16 13:31  那一抹风情  阅读(2935)  评论(0编辑  收藏  举报