0

I have a SwiftUI app that launches WKWebView for Twitter, Facebook, etc. The same view in an App Clip won't launch the WKWebView. I tried SFSafariViewController too. These are not listed as frameworks that provide limited to no functionality at runtime for App Clips. Any ideas?

struct WebViewButton: View {
    let urlString: String
    let buttonText: String
    let buttonImage: String
    let navText: String

    var body: some View {
        NavigationLink(destination: SafariView(url: urlString)) {
            HStack {
                Image(buttonImage)
                    .resizable()
                    .frame(width: 20, height: 20)
                Text(buttonText)
                    .font(.system(size: 14))
                }
                .padding()
        }.buttonStyle(ButtonBackgroundStyle())
         .navigationBarTitle(Text(navText))
    }
}


struct SafariView: UIViewControllerRepresentable {
    let url: String

    func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
        return SFSafariViewController(url: URL(string: url)!)
    }

    func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {}
}
Andrew
  • 26,706
  • 9
  • 85
  • 101
Jim Peters
  • 281
  • 3
  • 8

1 Answers1

1

Epiphany this morning! The problem was not with WKWebView or SafariViewController. The problem was the App Clip view which has the NavigationLink was not launched from the app that had the associated NavigationView. Adding the NavigationView to the App Clip launch solved the problem:

var body: some View {
        NavigationView {
            clipView(hasKey: model.selectedCity)
        }.navigationBarTitle(Text("CoSD Community Readiness"), displayMode: .inline)
        .navigationBarColor(.systemRed)
        .navigationBarHidden(false)
    }
Jim Peters
  • 281
  • 3
  • 8