4

Basically I want to retrieve files (e.g. pdf) from other apps (e.g. dropbox) to store and modify later.

I wrote a share-extension for that task and could iterate over NSExtensionItem's and can catch out my files - but I have no idea about their original filename.

I noticed that other apps got the filename - but they're called with the "open with" function in iOS.

So how I get the filename in my share-extension?

Thanks in advance.

1 Answer 1

6

You have the filename as lastPathComponent in the URL received:

    itemProvider!.first!.loadItemForTypeIdentifier(kUTTypeImage as String, options: nil, completionHandler: {
        (provider, error) in
        let url = provider as! NSURL

        println(url)

        let data = NSData(contentsOfURL: url)

        let name = url.lastPathComponent!

        ...

        // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
        self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
    })
Sign up to request clarification or add additional context in comments.

1 Comment

This works well on iOS Share extension, but not on macos share extension. On MacOS share extension - provider is always returned as of type Data

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.