Reputation: 6119
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
Upvotes: 3
Views: 1942
Reputation: 6119
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)
}
})
Upvotes: 5