ios - 使用 ifndef 和 || 进行条件编译没有捕获第二种情况

标签 ios objective-c conditional-compilation

当设置了两个定义中的一个或两个时,我试图禁用自动崩溃日志报告:DEBUG 用于我们的调试构建,INTERNATIONAL 用于国际构建。但是,当我尝试在 #ifndef 情况下这样做时,我收到警告 Extra tokens at end of#ifndef directive and running with DEBUG 定义将触发 Crittercism。

#ifndef defined(INTERNATIONAL) || defined(DEBUG)
    // WE NEED TO REGISTER WITH THE CRITTERCISM APP ID ON THE CRITTERCISM WEB PORTAL
    [Crittercism enableWithAppID:@"hahayoudidntthinkidleavetherealonedidyou"];
#else
    DDLogInfo(@"Crash log reporting is unavailable in the international build");

    // Since Crittercism is disabled for international builds, go ahead and
    // registers our custom exception handler. It's not as good sadly
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    DDLogInfo(@"Registered exception handler");
#endif

这个真值表显示了我的预期:

INTL defined | DEBUG defined | Crittercism Enabled
     F       |      F        |    T
     F       |      T        |    F
     T       |      F        |    F
     T       |      T        |    F

这在它只是 #ifndef INTERNATIONAL 之前是有效的。我也尝试过不使用 defined(blah) 并在整个语句周围加上括号(分别是相同的警告和错误)。

如何从编译器获得我想要的行为?

最佳答案

你想要:

#if !defined(INTERNATIONAL) && !defined(DEBUG)
    // neither defined - setup Crittercism
#else
    // one or both defined
#endif

或者你可以这样做:

#if defined(INTERNATIONAL) || defined(DEBUG)
    // one or both defined
#else
    // neither defined - setup Crittercism
#endif

关于ios - 使用 ifndef 和 || 进行条件编译没有捕获第二种情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535706/

相关文章:

ios - Xcode 9 GM 种子模拟器屏幕人工制品

objective-c - 执行获取请求 :error: causes an uncaught exception 'NSRangeException'

c# - 如何在Visual Studio中为不同的编译宏设置不同的资源?

rust - 如何排除在 OS X 上构建文件?

conditional-compilation - 为什么我无法#ifdef stdafx.h?

ios - 从 UIFont 或 CGFont 获取元信息 - iOS、Swift

ios - ITMS-90086 "Missing 64-bit support"将 Adob​​e Air 应用程序上传到 iTunes Connect 时出错

ios - 为 UIImageView 旋转 180 度,并以相同的路线旋转回来

ios - 为上传的内容提供的 MIME 类型无效(Google 云端硬盘、iOS)

ios - SKAction序列临时延迟(初始延迟?)