当我使用SKStoreReviewController.requestReview()从我的SwiftUI应用程序中的场景代理请求一个评论时,我得到以下消息:Error in UIKit client: -[UIWindow setScreen:] should not be called if the client adopts UIScene lifecycle. Call -[UIWindow setWindowScene:] instead.。
我在现场委托中使用以下代码请求评审:
if let windowScene = scene as? UIWindowScene {
if UserDefaults.standard.integer(forKey: "launchCount") == 10 {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: homeView)
self.window = window
window.makeKeyAndVisible()
if #available(iOS 14, *) {
SKStoreReviewController.requestReview(in: windowScene)
}
else {
SKStoreReviewController.requestReview()
}
}
}此代码位于场景代理的scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)方法中。iOS 14的方法是在从UIWindowScene请求检查的情况下工作的,但是早期版本的方法不起作用,并返回前面指定的消息。有办法解决这个问题吗?提前谢谢你的帮助。
发布于 2022-09-27 17:36:45
您可以使用我的SKStoreReviewController小包装器来解决这个问题。
import SwiftUI
import AppReview
struct ContentView: View {
var body: some View {
VStack {
Text("SwiftUI")
}.onAppear {
AppReview.requestIf(launches: 3)
}
}
}https://stackoverflow.com/questions/66726515
复制相似问题