Created
May 1, 2024 15:42
-
-
Save takoikatakotako/5eabddb391b49491778373e0321ef2f4 to your computer and use it in GitHub Desktop.
SwiftUIでUIActivityViewControllerを表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ActivityViewController: UIViewControllerRepresentable { | |
var activityItems: [Any] | |
var applicationActivities: [UIActivity]? = nil | |
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController { | |
let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities) | |
return controller | |
} | |
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State private var showingActivityIndicator: Bool = false | |
var body: some View { | |
Button("Share swiswiswift.com") { | |
showingActivityIndicator = true | |
} | |
.sheet(isPresented: $showingActivityIndicator) { | |
ActivityViewController(activityItems: [URL(string: "https://swiswiswift.com")!]) | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment