Swiftui Share Sheet Crashes iPad

Share Sheet Crashing on iPad

I implemented share sheets today as well and had the exact same issue. You need to add this before presenting.

if let popoverPresentationController = activityController.popoverPresentationController {
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = CGRect(x: CGRectGetMidX(view.bounds), y: CGRectGetMidY(view.bounds), width: 0, height: 0)
popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0) //Removes arrow as I dont want it
}

Line 1 sets the source view.

Line 2 I use to Center the popover right in the middle (I use it in SpriteKit and the popover is not attached to anything)

Line 3 I use to remove the arrow as I don't want it.

Hope this helps

Present ActionSheet in SwiftUI on iPad

Finally, as tested in iOS 13.4 this has been resolved, at least in the beta. The conflicting constraints warning persists, but the crash is gone. This is now the appropriate way to present an action sheet.

import SwiftUI

struct ContentView : View {
@State var showSheet = false

var body: some View {
VStack {
Button(action: {
self.showSheet.toggle()
}) {
Text("Show")
}
.actionSheet(isPresented: $showSheet, content: { ActionSheet(title: Text("Hello"))
})
}
}
}

struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}


Related Topics



Leave a reply



Submit