Re: macOS Drag and Drop onto App Icon


Marco S Hyman
 


My problem is finding a correct (App Store approval) method to enable drag and drop to the App Icon.
I thought this was answered earlier. Implement this in your app delegate

// MARK: Open File (UTI support)

/// process files give to us via "Open With..."
///
/// - parameter sender: unused
/// - parameter fileName: path of file to process
/// - returns: true if the file was opened
///
/// If multiple files are specified the function appears to be called once per file.

func application(_ sender: NSApplication,
openFile filename: String) -> Bool {
let url = URL(fileURLWithPath: filename)
/// do something with URL Return true if OK

return false
}

I think that is all that is necessary.

And with that, a caveat. My “do something” code happens to eventually contain this:

updateGroup.enter()
DispatchQueue.global(qos: .userInitiated).async {
// some code
DispatchQueue.main.async {
// more code
updateGroup.leave()
}
}

When I drag a file onto the app icon my app dies with

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 1'
abort() called
terminating with uncaught exception of type NSException

I don’t think it did that before I added the DispatchQueue. I just discovered this. Something else to debug.

Marc

Join cocoa@apple-dev.groups.io to automatically receive all group messages.