16
votes

I want to share a file using the Share Sheet and have written code that seems to work just fine. However I keep seeing these error messages in the log (using Xcode 11.3)

[ShareSheet] connection invalidated

I have two physical devices I'm testing on; an iPad running iOS 13.1.2 and an iPhone 6 running 11.4. I don't see these messages on the iPhone with the older iOS on it. Both cases the sharing seems to work just fine. Here's the code I'm using using text instead of a file:

let activityViewController = UIActivityViewController(activityItems: ["simple text for test"], applicationActivities: nil)
activityViewController.excludedActivityTypes = [.message, .airDrop]
activityViewController.popoverPresentationController?.barButtonItem = myBarButtonItem           
self.present(activityViewController, animated: true, completion: nil)

The message shows up when the share sheet goes away (either because user completes an action, or they tap outside of it to cancel).

Is it safe to ignore these messages? It's just odd that they didn't show up in the older OS but do in the new one.

Edited on 20 Mar 2020: I validated that I was providing a valid source or barButtonItem. I've changed the code to match that where I'm using a UIBarButtonItem and I still see the ShareSheet connection invalidated error.

2
I'm having the same issue. And some users claim that the share sheet won't show up. But my test device is working well.Kimi Chiu

2 Answers

9
votes

I got

[ShareSheet] connection invalidated

in the Xcode output log on iOS 13.x, and the share sheet was squished and did not have any buttons in it.

To fix it, assign your sourceView to something more specific than self.view

In my case, I had some UILabels near the top of my view, so I set my sourceView to one of those. For example, in my parent view controller, I had a UILabel named labelCustomerName so I used that:

activityViewController.popoverPresentationController?.sourceView = self.labelCustomerName
3
votes

For me, it was solved when i added this code, based on Apple developer documentation.

activityViewController.isModalInPresentation = true

By the way, it seems like even if press the close button for the activity it still shows that message.