Sharing a file

Is it possible to use the sharing panel to share a file?
I’m guessing I could upload a file to a server and pass the URL, but I’d like to be able to share the file itself.

Optionally I can send some text representing the file but then I suspect anyone receiving it will have a mess to deal with.

Any suggestions?

Drag a sharing panel to a form.

Then in code, do something like this: (I use this code to create and share a CSV file)

[code]SharingPanel1.ShareText thetextvariable, self, me


That’s just text though.
Wouldn’t it show up in the body of an email just as a long string?

With iOSKit you can use the UI classes bare metal. It works but I’m not sure that an example project exists

I will take a look. Thanks, Jason.

@Jason King , I’m not seeing which classes you are referring to. Can you be a bit more specific?

dim controller as UIActivityViewController dim url as Foundation.NSURL = Foundation.NSURL.FileURLWithPath(myFile.Path) controller = new UIActivityViewController(NSArray.CreateWithObject(url),nil) //present with nil completion handler self.PresentViewController(controller, True, nil)

Do you know if there are any limitations or restriction on where the file can be located to to this?
Thank you very much for taking the time to write it up.

Not sure. If you put it in the SpecialFolder.documents folder I think you should be fine

Well that works like a charm! Thanks

This begs the next question of how to register a file type so it will open with my app.
I’ll browse the forum for this one.

Welcome. I don’t think you’ll find registering file types on the forum sadly. Apples directions are here:

You might have to do it in Xcode to make your plist correct since I’m pretty sure its just modifying the plist. But I haven’t done this in Xojo before.

That was a good reference and helped me understand what I need to do. I did use Xcode and it was a PITA and didn’t work.
I did, however find this link and could hack that to work.


Now I can send myself the file and it shows up with my application icon (cool).
By messages, it won’t open.
By mail, I can tap on it, and can get to my app via the More… button.

  1. how do I get my app to show up in the default list as there is no ambiguity with the file extension
  2. when I do send it to my app, I have zero idea how to get an event to fire with any data that I can process.

Anyone able to help?

Not sure. Its probably on SO though

In the open event of the app, create a Foundation.NSDictionary object from the pointer passed to you. This will be the launch options dictionary. Then you need to inspect this key to get the URL of the file to open:
The string value is “UIApplicationLaunchOptionsURLKey” which you can find with a swift playground in Xcode.

Untested but should be something like:

dim d as new Foundation.NSDictionary(launchOptionsHandle) dim fileURL as new Foundation.NSURL(d.Value("UIApplicationLaunchOptionsURLKey")) dim f as new //might be absoluteString, I don't remember // process the file
You also need to have some error checking so this doesn’t crash if the key isn’t present. But that shouldn’t be difficult

That looks like it’s on the right track, but this line fails, and I can’t figure out what the key value should be. Ptr to what?
The compiler complains about the text literal.

Dim fileURL As New Foundation.NSURL(d.Value("UIApplicationLaunchOptionsURLKey"))

Convert to NSString

This is the solution:

[code]Dim d As New Foundation.NSDictionary(launchOptionsHandle)

Var k As New Foundation.NSString( “UIApplicationLaunchOptionsURLKey” )

Dim fileURL As New Foundation.NSURL(d.Value(k))

Var t As Text = fileURL.path
If t.empty = False Then
Dim f As New
// deal with the file
End If[/code]

@Jason King , I found it and posted the solution just as you sent this.

It works like a charm.

Now I just need to figure how how to make my app show up in the default list of apps to handle it.

PS: This should be handled right from within Xojo without so much extra jumping through hoops.

OK, I lied. It only works if the app isn’t currently running. If it’s running the open event never fires again.

I think the ImprovediOSApplication posted by Jason has an OpenURLOptions event for the app that will let you get the URL if the app is already open.

Hmmm. I’m using his code, which I’ve downloaded recently (most current?) but I can’t find that class in there anywhere. I do see other threads referencing it too.
This stuff really does need to be integrated right into Xojo.