share extension loading a mail pdf attachment stopped working. It did work perfectly well up to 2 months ago.
The offending line is:
// load the address of the data
let url = data as! NSURL
in console error is:
2019-12-22 15:03:44.575068+1300 coolpayShareExtension[20397:525435] [core] SLComposeServiceViewController got NSURL file:///var/tmp/com.apple.email.maild/EMContentRepresentation/com.apple.mobilemail/76F2A9FB-7EFE-425F-AEB4-9C988AAC4A61/Invoice%20INV-6840.pdf for public.file-url error: (null)
2019-12-22 15:03:44.617204+1300 coolpayShareExtension[20397:525204] [core] SLComposeServiceViewController got attachment coarseType 0
2019-12-22 15:03:44.617325+1300 coolpayShareExtension[20397:525204] [core] SLComposeServiceViewController made no attachment for itemProvider conforming to public.file-url
Could not cast value of type '_NSItemProviderSandboxedResource' (0x1d2c89e60) to 'NSURL' (0x1d5072dd0).
2019-12-22 15:03:44.917142+1300 coolpayShareExtension[20397:525436] Could not cast value of type '_NSItemProviderSandboxedResource' (0x1d2c89e60) to 'NSURL' (0x1d5072dd0).
Here is the code:
// load and save the data
func dataAttachment() {
// extract the first item of contents of the share extension
let content = extensionContext?.inputItems[0] as! NSExtensionItem
// we are only loading pdfs
let contentType = "com.adobe.pdf" // kUTTypePDF as String
// loop through all attachments
for attachment in content.attachments! {
// if it is a pdf
if attachment.hasItemConformingToTypeIdentifier(contentType) {
// upload it
attachment.loadItem(forTypeIdentifier: contentType, options: nil ) { data, error in
// if there is no error
if error == nil {
// load the address of the data
let url = data as! NSURL
// if there are valid data
if let imageData = NSData(contentsOf: url as URL) {
// save them
self.saveDataToUserDefault(suiteName: self.groupName, dataKey: "pdfData", dataValue: imageData )
} // if let imageData = NSData(contentsOf: url as URL)
} else { // there is an error
// show alert
self.showMessage(title: "sorry", message: "could not load the pdf", VC: self)
} // if error == nil
} // attachment .loadItem(forTypeIdentifier: contentType, options: nil )
} // if attachment.hasItemConformingToTypeIdentifier(contentType)
} // for attachment in content.attachments!
} // func dataAttachment()
Can anyone help please?