首页 > 解决方案 > 在 macOS Catalina 中拖放磁盘

问题描述

我有一个 macOS 应用程序,用于接受磁盘拖放以及 DMG 文件。从 Catalina 开始,它不再接受磁盘,但 DMG 文件仍然像以前一样工作。我尝试了全盘访问,但行为没有改变。

这是我的 plist 文件的摘录:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>dmg</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>dmg</string>
        <key>CFBundleTypeRole</key>
        <string>Shell</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>disk</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>disk</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Shell</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
    </dict>
</array>

接收事件的代码没有改变,仍然适用于 DMG 文件:

func applicationDidFinishLaunching(_: Notification) {
    let event = NSAppleEventManager.shared().currentAppleEvent

    if event?.eventID != AEEventID(kAEOpenApplication) {
       NSApp.terminate(self) // in this case user used drag and app is just reaching this point after everything is set and done
    } else {

有任何想法吗?

更新 10/27 事实证明,我必须更新一些过时的密钥并通过 Finder 导出和测试,而不是通过 Xcode 运行。如果我尝试后者,它不会“尊重”新的 plist 条目。诡异的。这是 plist 文件的更新部分:

    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>diskimage</string>
            <key>CFBundleTypeRole</key>
            <string>Shell</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.disk-image</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeName</key>
            <string>disk</string>
            <key>CFBundleTypeRole</key>
            <string>Shell</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.volume</string>
            </array>
        </dict>
    </array>

标签: swiftmacosdragdiskmacos-catalina

解决方案


推荐阅读