Action Extension on Mail App returns _NSItemProviderSandboxedResource on iOS13

When we use action extension with iOS13 Mail app, we don’t get the file url of the selected file. Instead we get it as _NSItemProviderSandboxedResource.


The action extension works with other apps like DropBox(PDF) , Photos(PNG) etc but only with Mail it doesn’t.



guard let inputItem = self.extensionContext?.inputItems.first as? NSExtensionItem, let provider = inputItem.attachments?.first else {
         
            return
        }
       
        if let typeIdentifier = provider.registeredTypeIdentifiers.first {
            provider.loadItem(forTypeIdentifier: typeIdentifier, options: nil, completionHandler: { [weak self] (fileURL, error) in
               
                OperationQueue.main.addOperation({
                   
                    print(fileURL as Any)
                    guard let fileURL = fileURL as? URL else {
                         
 here                        ///On iOS13 mail app Its not a file URL. HOW Do we handle this  . We get _NSItemProviderSandboxedResource
                       
                        //This is not an URL
                        fatalError()
                    }
                    print(fileURL)
               //fileURL is proper in iOS12
                })
            })
        }

Replies

I found the solutuon


Just need to replace

if let typeIdentifier = provider.registeredTypeIdentifiers.first

with

if let typeIdentifier = provider.registeredTypeIdentifiers.last

Looks like Apple mail app on iOS13 returns multiple type identifiers. You might want to check which of them works out in the array of

registeredTypeIdentifiers