Share a PDF (or any file) through UIActivityViewController

My App creates PDF reports and I would like to enable the user to add the PDF to iBooks and send it by email. (Note, the PDF is generated online and downloaded to the App).

I tried following the example provided here: http://stackoverflow.com/questions/37990711/use-of-uiactivityviewcontroller-and-uiactivityitemprovider-to-share-pdf

First the file is downloaded and it is then shared using UIActivityViewController from iOSKit:

[code] //create the view controller
using Extensions
using Foundation
using UIKit
dim controller as UIActivityViewController
//create the controller -> create a single item array with an nsobject representing the image
//the second parameter is an NSArray of custom UIActivity objects, just pass nil since custom object
//UIActivity creation is difficult in xojo

	//Try with NSData but it fails
	Dim data As NSData = NSData.DataWithContentsOfFile(file.path) //file is a xojo.io.Folderitem in the View
	Dim fileArr As NSArray = NSArray.CreateWithObject(data)
	
	controller = new UIActivityViewController(fileArr, nil)
	
	//present with nil completion handler
	self.PresentViewController(controller, True, nil) //Crashes after this line[/code]

But the App crashes as soon as the UIActivityViewController is supposed to be presented.

Example project: https://www.dropbox.com/s/58744avxf1zt06l/pdfTest.xojo_binary_project?dl=0

Hi Jrmie,
did you tried to use the Xojo control iOSSharingPanel?

Hi Antonio,

iOSSharingPanel has only three methods:
SharePicture
ShareText
ShareURL

None of them can share a folderitem.

It should be an URL (try “file://”+theFile.path)

I had tried that in the simulator but of course the simulator only has limited options.

Thank you very much Antonio, problem solved.

And I hadn’t realised that the example in iOSKit produces the same crash. So it wasn’t my code.

The crash you’re seeing was recently reported to me so I’m working on a solution. The view must be presented in a popover on iPad.

Jason, with your explanation about the crash I was able to fix it. I’ll share my code in a private thread so you can update iOSKit