Linking to the App Store nicely / by Jake MacMullin

You may have occasion to want to send people to Apple's App Store from within your app. Perhaps you're recommending another app or the user has indicated she'd like to rate your app. If you find yourself in this situation, here's how you can do it nicely.

In iOS6 Apple introduced an API for displaying an app store page from within your app. This is much nicer than using a URL that causes your app to close and the App Store app to open and it is much, much nicer than using a URL that causes Safari to open momentarily before causing the App Store app to open.

Here's what you need to do. 

1. Add the StoreKit framework to your project. 

2. Initialise an SKStoreProductViewController, configure the delegate and ask it to load the details of the product you want to show to your user. 

 

SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
[storeViewController setDelegate:self];

NSDictionary *productParams = @{ SKStoreProductParameterITunesItemIdentifier : @"401778175" };
[storeViewController loadProductWithParameters:productParams completionBlock:^(BOOL result, NSError *error) {
if (result == YES) {
[self presentModalViewController:storeViewController animated:YES];
} else {
// handle the error
}
}];

3. Finally, make sure you implement the SKStoreProductViewController's required delegate method.

 

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissModalViewControllerAnimated:YES];
}

That's it. Now when your user has finished looking at the app you're showing her she can return to whatever she was doing in your app with a single tap.