3

My share extension for macOS takes image or video files.

I'd like to be able to access the filename (or path) for the NSItemProvider object.

I've figured I can use itemProvider.loadDataRepresentation() to get the data for the media. However its not clear to me how to retrieve the filename/path.

When I print the itemProvider object, I get this:

<NSItemProvider: 0x600002998d20> {types = (
    "public.jpeg",
    "public.file-url",
    "public.url"
)}

Any help appreciated. Thanks

1 Answer 1

5

Figured it out.

                    itemProvider.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil, completionHandler: {
                        (data, error) in
                        if let url = URL(dataRepresentation: data as! Data, relativeTo: nil){
                            let filename = url.lastPathComponent
                            print(filename)
                        }
                    })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.