10

I'm implementing the StoreKit in-app app purchase interface and though it appears that the SKStoreProductViewController handles landscape on iPad, it does not appear to do so for my app on iPhone (it's universal).

The interface to SKStoreProductViewController is so limited, I don't appear to be able to manipulate the VC in any way. Has anyone else run into this? Any work-arounds?

When I run the code that works on iPad, the SKStoreProductViewController comes in from the left side, about an inch, and hangs out there until dismissed. It seems functional, but it messes up the VC that popped it up upon dismissal.

Here's the code:

// Set up the store vc (creating it if not already done)
if (self.storeVC == nil) self.storeVC = [[SKStoreProductViewController alloc] init];
self.storeVC.delegate = self;
NSDictionary *params = [NSDictionary dictionaryWithObject:appID forKey:SKStoreProductParameterITunesItemIdentifier]; 

// Set up a HUD in case connecting to the store takes a while
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; 

[self.storeVC loadProductWithParameters:params
                        completionBlock:^(BOOL result, NSError *error) {
       [MBProgressHUD hideHUDForView:self.view animated:YES];
       if (result) {
           [self presentViewController:self.storeVC animated:NO completion:^{
           }];
       }
  }];

Even better, we're having the same problem on the GKHostedAuthenticateViewController which is the viewcontroller returned from the method:

GKLocalPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error) {};

To reiterate: both of these are in portrait mode on iPhones (but not iPads) and they force the UI to go into portrait mode. Upon returning, your app's UI is messed up.

2
  • 1
    I just ran into a similar problem now. I'm making an iPhone app in landscape only mode. Firing up a SKStoreProductViewController to view another iOS app in the store - the SKStoreProductViewController doesn't really look good - there are three tabs that select the contents of the below scrollview. The scrollview does not use the full landscape width which makes it look... half-assed, I don't think there is any other word for it.
    – Jonny
    Dec 10, 2012 at 13:42
  • 1
    @Jonny and what's more, on the latest ios 7, the skstoreproductviewcontroller actually crashes on landscape mode
    – OMGPOP
    Jul 10, 2013 at 8:57

2 Answers 2

5

I ran into a similar problem. My universal app is in landscape, but while the SKStoreProductViewController works fairly well in landscape on the iPad, it presents with visual glitches on the iPhone.

My solution was to force the iPhone to present the SKStoreProductViewController in portrait. It's a little sad that it doesn't have the same orientation as the rest of the app, but it's better than having half the screen cut off.

I accomplished this by using the custom subclass below:

@interface SKPortraitStoreProductViewController : SKStoreProductViewController
@end

@implementation SKPortraitStoreProductViewController
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
        return UIInterfaceOrientationPortrait;
    else
        return [super preferredInterfaceOrientationForPresentation];
}
@end
2
  • But app crashes on iphone iOS 7. I am stilling looking for the solution.
    – Emmy
    Nov 1, 2013 at 20:13
  • Me too. Has anyone succeeded in using the SKStoreProductViewController on iOS 7 on landscape app?
    – Mayoneez
    Mar 24, 2014 at 11:03
0

Try changing the modalPresentationStyle property on your SKStoreProductViewController before presenting it.

I have had good luck by setting it to UIModalPresentationPageSheet which seems to cover the landscape iPad case pretty well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.