File shared via AirDrop is incomplete

309 views Asked by At

I am working on an application one of the features of which is downloading and displaying PDF files. I had no problems implementing these features. Then I wanted to enable sharing of the files but ran into a strange problem.

Here's how my sharing code looks like:

log.debug("Will share file: '\(fileURL.absoluteString)'")
// an example of fileURL: file:///var/mobile/Containers/Data/Application/3A6D5948-8F14-42FB-905A-D776BD975ED1/Library/Caches/d7e635bb-5baa-4fde-b60b-b3fb869cdf46/6.3%20Rambeskrivning%20Mark.pdf

let shareView = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
dependencies.router.show(shareView, asPopoverFrom: barButtonItem)

Nothing fancy, but when I share the file via AirDrop, it is only 200-250 bytes on the receiving end and has a different name, something like "PDF document-373E47D68169-1.pdf" (instead of the original name).

My first thought was that the downloaded document is corrupted, but it is not (I checked both on a device and a simulator). If I choose another sharing option (for instance, "Save to Files"), the file is shared correctly. UIDocumentInteractionController exhibits the same behavior. I also thought this might be caused by not retaining the UIActivityViewController (UIDocumentInteractionController requires this for the AirDrop sharing to work), but letting the system do this seems sufficient.

The issue is reproduced on both iOS 12.1 and 11.4.1.

What am I missing?

1

There are 1 answers

0
Onne van Dijk On

I ran into this exact same issue where everything worked except AirDrop. Turns out my URL instance was relative which somehow caused a problem with AirDrop. I solved it by passing activityItems: [fileURL.absoluteURL].