SwiftUI ShareLink in sheet is not woring

217 Views Asked by At

I'm trying to add the ability for a user to share image to firends.

I have a sheet for share using ShareLink.

I got two issues.

ISSUE-1 : Couldn't load file URL

2023-09-05 12:40:10.458253+0800  [ShareSheet] Couldn't load file URL for Collaboration Item Provider:<NSItemProvider: 0x600000c80b60> {types = (
    "public.png",
    "public.jpeg"
)} : (null)

ISSUE-2 : Couldn't open share sheet. When i get the first issue , i try to change the item to URL in ShareLink, but it not woring too.

2023-09-05 12:40:10.515938+0800 [86420:31521358] [Presentation] Attempt to present <UIActivityViewController: 0x7fc8dc81f800> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x7fc8dc830a00> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_VVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier_GVS_18StyleContextWriterVS_19SidebarStyleContext___: 0x7fc8cc831c00>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x7fc8bc864000>.

How to solve these issues?? Thanks all

My code is here:

From MainView.fullScreenCover -> DetailView.fullScreenCover -> ShareInventoryView

struct ShareInventoryView: View {
    @Environment(\.presentationMode) var presentationMode
    @State private var renderedImage = Image(systemName: "photo")
    @Environment(\.displayScale) var displayScale
    
    var inventory:Inventory
    
   
    var body: some View {
        VStack {
            
            ScrollView{
                renderedImage
            }.padding()
            

            
 
       ShareLink("Export", item: renderedImage, preview: SharePreview(Text("Shared image"), image: renderedImage))


        }
        .onAppear { render() }
    }

    @MainActor func render() {
        let renderer = ImageRenderer(content: RenderView(text: text, inventory: inventory))

        // make sure and use the correct display scale for this device
        renderer.scale = displayScale

        if let uiImage = renderer.uiImage {
            renderedImage = Image(uiImage: uiImage)
        }
    }
}

enter image description here

What can i do to solve these issues??

0

There are 0 best solutions below