Error "[Sharesheet] Connection Invalidated" Error iOS13+ But Not on iOS 11.4

Force dismiss iOS share sheet manually Swift iOS 8 and 9

If iOS Share Sheet is displayed, and call this method:
self.dismissViewControllerAnimated(true, completion: nil) share sheet is dismissed successfully.

Unable to share multiple images using share sheet Swift

You create a bunch of UIActivityViewController to show inside your loop from your code so only first of them will be shown because next are skipped.
You should create array of images to share first and then show the controller with this array.

// Prepare array of images to share
var images = [UIImage]()
for i in 0...scan.pageCount-1 {
...
images.append(reloadedImage!)
}
// Create and present single activity controller
let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil)
...
self.present(activityViewController, animated: true, completion: nil)

How to open Share Sheet from presented sheet

The problem is in trying to show second sheet from root controller. It already has one attached, so rejects another (which is Activity in this case).

The solution is to use own controller, placed in opened our sheet as a presenter for activity.

Here is a simple demo. Tested with Xcode 13 / iOS 15.

demo

struct SheetView: View {

@Binding var showSheetView: Bool
@State private var isShare = false
var body: some View {

// Below share Sheet - now works!
Button(action: {
isShare = true // present activity
}) {
Text("Share Me")
}
.background(SharingViewController(isPresenting: $isShare) {
let url = URL(string: "https://apple.com")
let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)

// For iPad
if UIDevice.current.userInterfaceIdiom == .pad {
av.popoverPresentationController?.sourceView = UIView()
}

av.completionWithItemsHandler = { _, _, _, _ in
isShare = false // required for re-open !!!
}
return av
})
}
}

struct SharingViewController: UIViewControllerRepresentable {
@Binding var isPresenting: Bool
var content: () -> UIViewController

func makeUIViewController(context: Context) -> UIViewController {
UIViewController()
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
if isPresenting {
uiViewController.present(content(), animated: true, completion: nil)
}
}
}


Related Topics



Leave a reply



Submit