Search code examples
swiftswiftuistorekitstorekit2

How can I fix screen freezing and excessive CPU usage when attempting to implement the "Request Review" feature


Have you encountered any solutions to address the issue of the screen freezing and excessive CPU usage when attempting to implement the "Request Review" feature in your project? Specifically, I'm facing this problem each time I switch from a screen containing the @Environment(\.requestReview) property to another screen using @ObservedObject.

I've also noticed that the _requestReview changed message is printed multiple times without any apparent reason, as shown in the screenshot below.

Consol showing changed

Do you have any suggestions or insights on how to troubleshoot and resolve this issue effectively?

here is a project to replicate the issue

https://github.com/byaruhaf/DefTest

or you can use the code below

import SwiftUI
import Foundation
import StoreKit

struct ContentView: View {
    var body: some View {
        let _ = Self._printChanges()
        VStack(spacing: 40) {
            Image(systemName: "soccerball")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Football School")
            NavigationLink {
                StudentListView()
            } label: {
                Text("Click for Student List")
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }
}

struct StudentListView: View {
    @Environment(\.requestReview) private var requestReview
    var body: some View {
        let _ = Self._printChanges()
        VStack(spacing: 40) {
            Text("Student List")
                NavigationLink {
                    StudentDetailView()
                } label: {
                    Text("Click for Student Detail")
                }
                .buttonStyle(.borderedProminent)
        }
        .padding()
    }
}
final class Test: ObservableObject {}

struct StudentDetailView: View {
    @ObservedObject var test = Test()

    var body: some View {
        let _ = Self._printChanges()
        VStack(spacing: 40) {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

High CPU

High CPU

Increasing Memory

Increasing Memory


Solution

  • issue Fixed in iOS 17.4 (FB13005087)