r.t.s.
r.t.s.

Reputation: 585

OSX - Get File Path from FileURL from Drag and Drop with Sandboxed application

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.

Upvotes: 2

Views: 876

Answers (2)

lcx_seima
lcx_seima

Reputation: 11

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];

Upvotes: 1

r.t.s.
r.t.s.

Reputation: 585

I found the solution using:

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

And yes the file was accessible from my Sandboxed application.

Upvotes: 0

Related Questions