SKStoreProductViewController

Hi,


I have a problem to open a StorePruduct.

my App running only in landscape orientation and I have this Code in my GLKViewController:

func showStoreProduct() {
        let productParameters = [SKStoreProductParameterITunesItemIdentifier : currentAppId]
        let storeViewController:SKStoreProductViewController = SKStoreProductViewController()
        storeViewController.delegate = self
        storeViewController.loadProductWithParameters(productParameters, completionBlock: { (success: Bool, error: NSError?) -> Void in
            if success {
                self.presentViewController(storeViewController, animated: true, completion: nil)
            } else {
                print("ERROR: storeViewController: \(error)")
            }
        })
    }

    func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
        viewController.dismissViewControllerAnimated(true, completion: nil)
    }


until yesterday code works fine.

Today always comes the error:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [SKStoreProductViewController shouldAutorotate] is returning YES'


Can someone please tell me what I’m doing wrong here ?

Answered by PBK in 98222022

I would guess that the skstoreproductviewcontroller only works in portrait and your code is trying to display it in landscape. I think you only need to implement the method they ask for: -(BOOL)shouldAutorotate and return 'no'.

Accepted Answer

I would guess that the skstoreproductviewcontroller only works in portrait and your code is trying to display it in landscape. I think you only need to implement the method they ask for: -(BOOL)shouldAutorotate and return 'no'.

Hi PBK,

thanks for the answer.


I have tried in my GLKViewController:

override func shouldAutorotate() -> Bool {
    return false
}

but without success.

I forgot a additional information, on devices iPhone 6 Plus and iPad no problem code works fine, only on iPhone 5s and iPhone 6 comes the error.


Any idea ?

Hi PBK,

I found a solution to the problem.

Generate a class called e.g. StoreProductViewController inherited from SKStoreProductViewController. Added function:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return [UIInterfaceOrientationMask.LandscapeLeft, UIInterfaceOrientationMask.LandscapeRight]
    }

In my GLKViewController in function showStoreProduct

change

let storeViewController:SKStoreProductViewController = SKStoreProductViewController()

to

let storeViewController = StoreProductViewController()

func showStoreProduct() {
        let productParameters = [SKStoreProductParameterITunesItemIdentifier : currentAppId]
        let storeViewController = StoreProductViewController()  
        storeViewController.delegate = self
        storeViewController.loadProductWithParameters(productParameters, completionBlock: { (success: Bool, error: NSError?) -> Void in
            if success {
                self.presentViewController(storeViewController, animated: true, completion: nil)
            } else {
                print("ERROR: storeViewController: \(error)")
            }
        })

this work fine.


nevertheless thanks for your response.

Just for kicks - what happens if you add the shouldAutoRotate method in your StoreProductViewController class instead of the supportedInterfaceOrientations method

Yes, you are right, shouldAutoRotate() also works.


Thank you for your feedback.

SKStoreProductViewController
 
 
Q