Group Group Group Group Group Group Group Group Group Forums

UIActivityViewController Tutorial: Sharing Data

In this UIActivityViewController tutorial, you'll learn all about giving your users the ability to export their data, and share it with others.

This is a companion discussion topic for the original entry at

Hi, I have a problem that I haven’t managed to solve. I have managed to export a datafile, and when I click on it it opens up the app, but the application function in AppDelegate.swift doesn’t run. I placed a print command in it to check, and it isn’t printing, so the function isn’t firing up. Any ideas as to where the problem might lie? I am integrating it all into another app, so it isn’t the tutorial project.

func application(
_ app: UIApplication,
open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
// 1
guard url.pathExtension == “btkr” else { return false }…

Hey! Can you try adding scene(_:openURLContexts:) to you UISceneDelegate, if you’re using iOS 13? I don’t have the ability to test this, but I have seen that since it came out, you might need to handle things there. You may want to see if you need to add anything else based on UIScene documentation.

Thanks. I did track down that I needed to use openURLContexts: , but I’m having trouble getting it to run. It isn’t called when opening the file. I’ll take a look at the UIScene documentation and see if I can work it out.

Hi again,

I have things running nicely in my simulator. Clicking a file saved to the Files App opens my app and imports the data, but for some reason it won’t work on my iPhone. I can create a backup file from my app and save it into the Files App, but when I try to import it I’m told that I don’t have permission to access that file. Any ideas as to what I might be causing this?

I’ve worked out that - outside of the simulator - with “open documents in place” set to NO, I can import the data from the file, via the share menu from in Files, but not when it is set to YES. I’m hazarding a guess it is because of private in the url link, as the error message says that permission isn’t granted to view the file:

Failed reading from URL: file:///private/var/mobile/Containers/Shared/AppGroup/FC9D99

Is there a way to rectify that?

@religionofpeas Do you still have issues with this?

Yes, I still have issues with it. I’m a bit tied up right now at work, but will give a rundown of where I’m at with it later tomorrow some time. I’d like to conquer this and gain a full understanding.


@owenb Can you please help with this when you get a chance? Thank you - much appreciated! :]

@religionofpeas I did some research on this and wasn’t able to find anything useful.
When you set ‘open documents in place’ to NO and it works, does this cause other undesirable side affects for your application?

Thanks, Owen

I have been doing a lot of experimenting with settings this morning and, I can’t say I have fully come to grips with it (I don’t know why it wasn’t working before), but it is working now with “open documents in place” and “supports file browsing” both set to yes. Tapping on a file, when it is standalone on my phone, opens the app and processes the file. So I’m pretty happy with it, and will leave it as is for the time being. I do have one issue though. I’d like my app to be set to not run in the background (this is the only way I’ve found to get TouchID to be called every time the app is closed and reopened), but when that is set to true the “openURLContexts” method does not get called. Do you know of a way to manually call it when the app is starting from scratch?

I’ve cracked my TouchID issue. I’m calling authenticateWithBiometric from sceneWillEnterForeground in the SceneDelegate, and it calls TouchID every time the app is closed and then reopened, and seems to be working smoothly. so it’s now safe to leave runs in background set to yes. I’m now just left with how to manually call openURLContexts if the app is actually fully closed. There must be an easy way to do it.

@religionofpeas Are you still having issues with this?