I'm playing around with using an app to automate some of my personal work flows, and one of the things I wanted to do was to be able to drag a .webloc
file onto my app icon in the dock, to launch it.
I've got public.data
set up as a document type for it in Xcode, which translated to
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
in the Info.plist
for it, which seems correct. When I drag a .webloc
file onto the Dock icon, it appears to be willing to accept it, but nothing seems to happen.
In the app, I've got an AppDelegate.swift
file which has
extension Notification.Name {
static let receivedURLsNotification = Notification.Name("ReceivedURLsNotification")
}
class AppDelegate: NSObject, NSApplicationDelegate {
func application(_ application: NSApplication, open urls: [URL]) {
guard !urls.isEmpty else { return }
NotificationCenter.default.post(name: .receivedURLsNotification, object: nil, userInfo: ["URLs": urls])
}
}
(I copied it almost verbatim from a Medium post.)
In the app swift file, I have
@main
struct LoggerApp: App, DropDelegate {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
I set a breakpoint on application(_:NSApplication, open:[URL])
, and did my drag, and the breakpoint never triggered.
I added the application(didFinishLaunching(_:Notification)
method, and that does get invoked when the app launches, so the app delegate does seem to be working. That seems to indicate the problem is somewhere else?