SKStoreProductViewController crashes for unrecognized selector named sceneDisconnected: in iOS 15.6 beta5

Viewed 4766

In iOS 15.6 beta5 and iOS 16.0 beta:

When an UISceneDidDisconnectNotification was posted, any active SKStoreProductViewController instance would crash for the unrecognized selector named sceneDisconnected.

-[SKStoreProductViewController sceneDisconnected:]: unrecognized selector sent to instance 0x115161a00

This crash only happened in the latest iOS15.6 and iOS16 beta version. Yet I can't find the selector name in any official documents……

Any solutions? Or Is there anything I haven't done right?

4 Answers

Looks like this was fixed in the iOS 15.6 release candidate that was realeased today.

Sept 14 2022 Update: Apple re-introduced this crash in the official 15.7 release. It only seems to happen when the app is force quit so it should not affect users. I've filed a ticket to Apple on feedbackassistant.apple.com and would encourage others to do the same.

Not a solution, but a clear indication that this is Apple's bug to fix. Starting with a clean sample project, all you need to do is present a SKStoreProductViewController and then force quit your application:

import StoreKit
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let storeKitViewController = SKStoreProductViewController()
        storeKitViewController.loadProduct(withParameters: [
            SKStoreProductParameterITunesItemIdentifier: NSNumber(integerLiteral: 364709193)
        ])
        present(storeKitViewController, animated: true)

        // Force quit after presentation to trigger crash
        // -[SKStoreProductViewController sceneDisconnected:]: unrecognized selector sent to instance
    }

}

I've filed this with Apple via Feedback Assistant.

This is actually an inaccurate reporting because it doesn't actually cause the crash.

I reproduced the reported scene: click on the app-download advertisement in your app, pop up the in-app App Store download page, and then back to the background, the crash message is generated in this time -- but no crash actually occurred, and nothing changed when I returned to the foreground. Everything works fine. The next time the app starts, the crash information will be reported.

So no need to do anything now, just wait for Apple to fix it.

Able to reproduce a crash with the same stack symbols locally and the code below stops the crash from occurring. The code is creating empty functions to handle the unrecognized selector message and restricting this extension to iOS 15.7:

@available(iOS, introduced: 15.7, obsoleted: 16.0)
@objc extension SKStoreProductViewController {
    func sceneDisconnected(_ arg: AnyObject) {}
    func appWillTerminate() {}
}
Related