之前一直用的这种,不知道为什么不怎么靠谱
#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 }() }
亲测,这种可以