我正在为我的 SwiftUI 应用程序构建一个信息页面。一个项目应该打开 App Store,另一个邮件。我为每个都编写了 UIViewControllerRepresentable 。
MailView 完全可以正常工作。StoreView 显示正常,但按下取消按钮时,抛出异常
“*** 由于未捕获的异常‘SKUnsupportedPresentationException’而终止应用程序,原因:‘SKStoreProductViewController 必须用于模态视图控制器’”。
MailView 可以很好地进入 didFinish 委托方法,但 StoreView 没有进入 didFinish 委托方法,它在进入这个 didFinish 方法之前崩溃了。请问我做错了什么?
import SwiftUI
import StoreKit
import MessageUI
struct InfoMoreAppsView: View {
@State var showAppAtStore = false
@State var reportBug = false
@State var result: Result<MFMailComposeResult, Error>? = nil
let otherAppName = "TheoryTest"
var body: some View {
VStack(alignment: .leading){
HStack{
Image(Helper.getOtherAppImageName(otherAppName: otherAppName))
Button(action: { self.showAppAtStore = true }) {
Text(otherAppName)
}
.sheet(isPresented: $showAppAtStore){
StoreView(appID: Helper.getOtherAppID(otherAppName: otherAppName))
}
} …Run Code Online (Sandbox Code Playgroud) swiftui ×1