1

When I use SKStoreReviewController.requestReview() to request a review from the Scene Delegate in my SwiftUI application, I get the following message: Error in UIKit client: -[UIWindow setScreen:] should not be called if the client adopts UIScene lifecycle. Call -[UIWindow setWindowScene:] instead..

I am using the following code in the scene delegate to request the review:

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()
        }
    }
}

This code is inside the scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) method of the Scene Delegate. The method for iOS 14 is working where the review is being requested from the UIWindowScene, but the method for earlier versions is not working and returns the message specified previously. Is there any way to fix this? Thanks in advance for all the help.

Todd
  • 500
  • 4
  • 10
  • `requestReview(in windowScene: UIWindowScene)` is available in only iOS 14 or higher. Since I am also supporting iOS 13 in my app and `requestReview()` is deprecated as of iOS 14 , I am using the availability check. iOS 13 and earlier uses `requestReview()` which returns the error message as stated in my question. – Todd Mar 20 '21 at 21:26

1 Answers1

0

You can use my small wrapper around SKStoreReviewController which solves this problem.

import SwiftUI
import AppReview

struct ContentView: View {
    var body: some View {
        VStack {
            Text("SwiftUI")
        }.onAppear {
            AppReview.requestIf(launches: 3)
        }
    }
}

https://github.com/mezhevikin/AppReview

user2168735
  • 395
  • 4
  • 14