I am building a third party library that is essentially an ad network, i.e., it will provide ads in apps. So, I need to allow users to install apps from within the app, using an ad - something like Facebook, where you see an app advertisement, you click that ad and install it - all within Facebook.
So I need to way to let users install those apps without leaving the app in which the ad is shown. Another recent example of this is Appsfire. They allow users to tap on ads, install those apps and return to Appsfire (essentially not letting the user leave).
I tried searching for an AppStore API but all I could find is the API to query AppStore, not a way to display an app and let users install it.
You're looking for SKStoreProductViewController
- which looks like this:
It works for apps, songs, books - anything on the iTunes store. Image credit techotopia.
This is a good tutorial on the subject - usage comes down to:
StoreKit
framework,Which comes down to this code:
SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
storeViewController.delegate = self;
NSDictionary *parameters = @{SKStoreProductParameterITunesItemIdentifier:[NSNumber numberWithInteger:<item id>]};
[storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
[self presentViewController:storeViewController
animated:YES
completion:nil];
}];
You can get your iTunes product ID using iTunes' LinkMaker. The ID is also shown under the Manage your Apps section of iTunes Connect:
The one required delegate method is a simple dismissal action:
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[viewController dismissViewControllerAnimated:YES completion:nil];
}