Error "[ShareSheet] connection invalidated" error iOS13+ but not on iOS 11.4

N.W picture N.W · Dec 21, 2019 · Viewed 8.3k times · Source

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.

Answer

Phill Z picture Phill Z · Jan 17, 2020

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