swift - 在 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>
解决方案
推荐阅读
- python - 从 Universal Robot 接收数据并解码
- php - graph.instagram.com 无法获取 follower_count
- python - 实例化和/或预填充 django 模型表单
- python-3.x - 如何解决 TypeError:'No Numeric Data to Plot',当 Python 中存在数值数据时
- amazon-web-services - AWS 状态机 - 更新 DynamoDB 表将 ID 替换为“$.id”
- asp.net-core - 在 Entity Framework Core 3.1 中将 DateTime 用于 SQL 时间列
- c++ - 是否可以从基类非虚拟方法使用派生类虚拟方法?
- javascript - 使用动态数据的滑块
- python - 在python的for循环中,为什么增量为负时不打印起点?
- c - 我可以从内核分配内存并从用户空间释放它吗?