Kodeco 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 https://www.raywenderlich.com/133825/uiactivityviewcontroller-tutorial

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
print(ā€œHyeheyheheyehspgidhā€)
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.

Cheers!

@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?