macOS应用程序在10.13崩溃,找不到符号:_NSAppearanceNameDarkAqua

问题描述

我正在使用Deployment Target 10.13构建一个macOS应用

可在10.15上运行,但在10.13上崩溃

Termination Reason:    DYLD,[0x4] Symbol missing

Application Specific @R_365_4045@ion:
dyld: launch,loading dependent libraries

Dyld Error Message:
  Symbol not found: _NSAppearanceNameDarkAqua

解决方法

有道理;直到10.14才引入深色模式。因此,如果您要在10.13上运行,则不得加载任何“内容”或依赖于明暗模式的内容-代码,资产目录或情节提要。

,

您需要根据正在执行的macOS版本,使使用此变量的代码:

if (@available(macOS 10.14,*)) {
    return NSAppearanceNameDarkAqua;
} else {
    return nil;
}

您也可以过时,将其声明为弱链接:

extern NSAppearanceName const NSAppearanceNameDarkAqua __attribute__((weak_import));
...
if (NSAppearanceNameDarkAqua!=NULL) {
    ...