1

I have created an SwiftUI app that used to fetch Olevel past-paper in website, and I use JSON to store the paper name and URL. It'll always return a pdf file on my application. And the problem is: I want to add an shared button in my detailed view(See the second picture) to let people share this pdf file to other people using AirDrop or Messenger app. But unfortunately, I can't find any useful content related to my problem although there're shared button everywhere...

import SwiftUI

struct OEng19ListView: View {

var body: some View {


    NavigationView {
        VStack{

                OEng19List()

        }
       .navigationBarTitle(Text("2019"))
    }
    .navigationViewStyle(StackNavigationViewStyle())

  }
}


struct OEng19List: View {
    var body: some View {
        List(OEng19Data) { xxx in

            NavigationLink(destination: OEng19Detail(xxx: xxx)) {
                OEng19Row(xxx: xxx)
            }
        }

    }
}



struct OEng19Row: View {
    var xxx: OEng19

    var body: some View {
        HStack {
            Text(xxx.name)
                .frame(width: 230, height: 45, alignment: .leading)
            Spacer()
        }
    }
}




struct OEng19Detail: View {
    var xxx: OEng19

    var body: some View {
        VStack {
            Webview(url: (xxx.url))
        }
        .navigationBarTitle(Text(xxx.name), displayMode: .inline)
    }
}

Here's my SwiftUI code about my listView and detailed view. Please help me, THANKS!!!

Also, the screen shot: enter image description here

enter image description here

I have tried the Safari Services, it can work well but I don't want to display the URL and other thing, just want to add the Share Function in that!!!

  • Add a navigation bar button to share web view contents. Follow this link for more help: [Bar Item in SwiftUI](https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-bar-items-to-a-navigation-view) – udbhateja May 09 '20 at 19:51
  • Hello, I've followed you and realized that I need to add a navigationBarItem, but I still don't know how to share my webView, please help me! – Zhu Patrick May 10 '20 at 04:24
  • You can't share a webView, you can only share the url or contents like title, image etc. – udbhateja May 10 '20 at 14:35
  • Yeah I mean share the pdf file based on the url, not the entire webView. For example, this url "https://papers.gceguide.com/O%20Levels/Computer%20Science%20(2210)/2210_s15_qp_11.pdf", it should be possible. – Zhu Patrick May 10 '20 at 14:58
  • 1
    Refer this post for help: [Sharing in SwiftUI](https://stackoverflow.com/questions/56819360/swiftui-exporting-or-sharing-files) – udbhateja May 10 '20 at 15:12

0 Answers0