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.
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
How to Write to a Variable from Within The Firebase Getdocument Function (Swift)
How to Access The Model Component of Reality Composer in Realitykit
Multiline Editable Text Field in Swiftui
Converting Scanlocation from Utf16 Units to Character Index in Nsscanner (Swift)
What Is Swift Enum Byte Representation
How to Change The Data Type in Realm Database
Vapor 3 - How to Check for Similar Email Before Saving Object
Swiftui: UIimage (Qrcode) Does Not Load After Calling Function
How to a Convert a Dictionary Slice to a Dictionary in Swift
Confusing About @Environmentobject in Swiftui
Xcode Issue: Library Not Loaded: @Rpath/Libswiftappkit.Dylib
How to Disable The Automatic Activation of an Arcoachingoverlayview
How to Emit Items, One by One, from Collection with a Delay in Rxswift
How to Use The Snapchat Sdk (Snapkit) with Swiftui