2

I am Using Drag and Drop to drop a File onto my APP.

Apple deprecated NSFilenamesPboardType in OSX 10.14 and suggests using NSPasteboardTypeFileURL.

The URL(String) I get is:

file:///.file/id=6571367.2682325

How do I get the Actual File Path from this URL ? I need File Name and Type info. Can I also access the File with the Full File Path ? I assume it is added to my Sandbox.

2 Answers 2

1

I'm working at Mac OS 10.14 with Xcode 10.2.

I got two solutions in performDragOperation (both registerForDraggedTypes with NSPasteboardTypeFileURL. Then):

  1. mentioned above

    [[NSURL URLWithString:relativePath] fileSystemRepresentation];

  2. init pasteBoard

    NSString *fileURL = [[NSURL URLFromPasteboard:pasteBoard] path];

1
  • This is the answer for a local path. An NSURL using the file protocol with an ID, will be correctly converted to a readable path string with the @(path) selector. It's not obvious but it does work.
    – AndyTang
    Commented Jan 31, 2023 at 14:13
0

I found the solution using:

NSURL * url = [NSURL initWithString:urlString];
NSString * path = [url fileSystemRepresentation];

And yes the file was accessible from my Sandboxed application.

Not the answer you're looking for? Browse other questions tagged or ask your own question.