Post

Replies

Boosts

Views

Activity

Reply to StoreKit purchase failed with UI anchor
Hello. I had the same problem as @Arideno - the issue mentioned in this forum only occurred during unit testing - and was able to fix it. Before each test, I created a mock window and attached it to a UIWindowScene. See my code below. private func setupMockWindow() -> UIWindow { DispatchQueue.main.sync { // Create a mock UIWindow. let mockWindow = UIWindow(frame: UIScreen.main.bounds) // Set a root view controller (can be a mock or real view controller). mockWindow.rootViewController = UIViewController() // Make the window key and visible. mockWindow.makeKeyAndVisible() // Attach the window to a UIWindowScene. if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { mockWindow.windowScene = windowScene } return mockWindow } } The created mock window has to be cached. So it is not possible to simply execute the method. It looks like StoreKit 2 needs a UI structure for it to work correctly. Best regards
Topic: App & System Services SubTopic: StoreKit Tags:
Mar ’25