Skip to content

Instantly share code, notes, and snippets.

@CH3COOH
Created September 26, 2024 11:28
Show Gist options
  • Save CH3COOH/fbd983b571ead7db9cf913896b5a2c1c to your computer and use it in GitHub Desktop.
Save CH3COOH/fbd983b571ead7db9cf913896b5a2c1c to your computer and use it in GitHub Desktop.
ContentView.swift
import SafariServices
import SwiftUI
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: Context) -> SFSafariViewController {
return SFSafariViewController(url: url)
}
func updateUIViewController(_: SFSafariViewController, context: Context) {}
}
struct ContentView: View {
@State private var isShowingSafariView = false
let url = URL(string: "https://blog.ch3cooh.jp/")!
var body: some View {
VStack {
Button(action: {
isShowingSafariView = true
}) {
Text("ブラウザを開く")
}
.fullScreenCover(isPresented: $isShowingSafariView) {
SafariView(url: url)
}
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment