gpt4 book ai didi

ios - 我如何知道 Objective-C 代码是否正在 iOS 模拟器中运行?

转载 作者:行者123 更新时间:2023-11-28 21:47:52 25 4
gpt4 key购买 nike

我试过了

#ifdef TARGET_IPHONE_SIMULATOR
static BOOL isSimulator = YES;
#endif

但是对于设备和模拟器,isSimulator 变量始终为 1。

我需要一种方法来确定运行的代码是在 iOS 模拟器上还是在设备上。

最佳答案

您的代码片段仅检查是否定义了 TARGET_IPHONE_SIMULATOR(即使它定义为 0)

尝试像这样检查:(#error 只会在 Xcode 中显示为编译错误)

#if TARGET_IPHONE_SIMULATOR
#error Simulator
#else
#error Device
#endif

关于ios - 我如何知道 Objective-C 代码是否正在 iOS 模拟器中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29441658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com