apple/sample-cloudkit-sharing

App crashes on iPad

mmklug opened this issue · 5 comments

When trying to share a contact from an iPad, the app crashes:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UISharingViewPresentationController: 0x100636430>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
terminating with uncaught exception of type NSException

Hi @mmklug, which version of Xcode and iOS are you using? These samples have been tested with Xcode 12.5 (and 13.0 Beta 1 for the swift-concurrency branch). The changes in #2 should fix your issue if you'd like to try out that branch, and please let us know if it continues to be an issue.

Hi @sjrmanning, unfortunately adding .navigationViewStyle(StackNavigationViewStyle()) did not solve the issue.
I am testing the code an iPad Air 2 on iOS 14.6 and the issue is present both using Xcode 12.5 and 13 beta 1.
Please note: when pressing on the share button, the "Add People" sheet appears as expected. But pressing on one of the offered options (e.g. "Copy Link") will cause the app to crash.
No issue on iPhone.

Got it, thanks for your response. I see where the crash is occurring and I've been able to reproduce it locally. The latest commits on that branch fix it by using an explicit presentationStyle on the wrapped controller, presenting as a form sheet rather than a popover presentation (the default in this case).

If you wanted to use a popover presentation for this view, you'd need a UIKit view to reference as the sourceView.

We've merged those changes in to main, but please feel free to re-open this if you still run into issues. Thanks!

Hi @sjrmanning,
this is working as expected now.
Thank you!