swiftui - 在 SwiftUI 的模态 .sheet() 中显示共享表(UIActivityViewController)
问题描述
我正在尝试从 SwiftUI 中的模态 .sheet() 中显示共享表。
共享表不显示;我收到以下错误:
[Presentation] Attempt to present <UIActivityViewController: 0x105012200> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10110b070> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10110b070>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x1038060d0>.
[ShareSheet] connection invalidated
如何使它从 .sheet() 显示
这是我的代码:
import SwiftUI
struct ContentView: View {
@State private var displayModal = false
var body: some View {
VStack {
Button("1. Share Sheet") {
shareSheet()
}.padding()
Button("2. Modal Sheet") {
displayModal.toggle()
}
.sheet(isPresented: $displayModal) {
Button("3. Inside Modal Sheet") {
shareSheet()
}
}
.padding()
}
}
func shareSheet() {
let items: [Any] = ["Share My App", URL(string: "https://www.apple.com")!]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(ac, animated: true, completion: nil)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
多谢你们。
解决方案
推荐阅读
- python-3.x - AttributeError:硒上的“NoneType”
- java - 为什么 Quartz Scheduler 在 x 分钟后停止在 Heroku 上工作?
- jquery - Zendesk Ticket 使用 ajax 创建 API
- php - PDFLib 已安装但在代码中不可用或通过 phpinfo() 可见
- android - Android BluetoothHeadset getConnectedDevices() 列表为空
- php - 从另一个相关表中的计数仅为一个的表中选择
- java - 哪个先中断,Mockito 还是 Java 泛型?
- linux - 使用读/写文件的管道()的替代实现
- android - RecyclerView 后按时不出现
- amazon-web-services - 在 aws.com 上手动删除后,无服务器 API 网关资源未恢复