应用程序在 macOS 10.13 上崩溃,并显示“DYLD,[0x4] 符号丢失”,尽管符号被包装在 @available(macOS 10.14.4, *) 中

问题描述 投票:0回答:1

我的代码中只出现了一次符号

kDADiskDescriptionMediaEncryptedKey
。它被一个
@available
块包围:

if (@available(macOS 10.14.4, *)) {
    CFStringRef x = kDADiskDescriptionMediaEncryptionDetailKey;
}

然而程序在 macOS 10.13 上崩溃了:

Date/Time:             2023-10-18 19:37:34.273 +0200
OS Version:            Mac OS X 10.13.6 (17G65)
Report Version:        12
Anonymous UUID:        C780E8BB-9F5C-A7EC-2846-AD51F8D2912C


Time Awake Since Boot: 2700 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x4] Symbol missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Symbol not found: _kDADiskDescriptionMediaEncryptedKey
  Referenced from: /Users/USER/Desktop/AvailableCrash.app/Contents/MacOS/AvailableCrash
  Expected in: /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration
 in /Users/USER/Desktop/AvailableCrash.app/Contents/MacOS/AvailableCrash

我在 macOS 13.6 (22G120) 上运行 Xcode 15.0 (15A240d)。该程序在此开发机器上按预期运行。

我做错了什么?

objective-c macos cocoa
1个回答
0
投票

因为你应该使用:

if #available(macOS 10.14.4, *) {
    CFStringRef x = kDADiskDescriptionMediaEncryptionDetailKey;
}

注意“available”前应使用“#”,而不是“@”。

© www.soinside.com 2019 - 2024. All rights reserved.