lukas
lukas

Reputation: 2410

Show App Store app page in app

There are some apps (like the free version of Cut the Rope) that present the App Store page of other apps directly in the app (probably using a modal view controller).
How do I implement this in my own app?

Example from Cut the Rope:

Upvotes: 1

Views: 238

Answers (2)

ZeMoon
ZeMoon

Reputation: 20274

One can implement a App Store page of any application within their own app by using the SKStoreProductViewController class.

NSString *strURL = @"" //Keep the App store URL here.
if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 6.0)
    {
        SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];

        NSRange range = [strURL rangeOfString:@"/id"];
        NSRange rangeID = {range.location + 3, 9};

        NSString *strAppID = [strURL substringWithRange:rangeID];
        NSLog(@"appid = %@", strAppID);

        // Configure View Controller
        [storeProductViewController setDelegate:self];
        [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : strAppID}
                                              completionBlock:^(BOOL result, NSError *error) {
                                                  if (error) {
                                                      NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);
                                                  } else {

                                                  }
                                              }];
        // Present Store Product View Controller
        [self presentViewController:storeProductViewController animated:YES completion:nil];
    }

The above code also extracts the app ID from the URL.

You can read about it in the class reference.

Upvotes: 1

Janak Nirmal
Janak Nirmal

Reputation: 22726

You can use SKStoreProductViewController for this, check out documentation for more detail

if ([SKStoreProductViewController class]) {
    NSString *yourAppID = @"";//Give your app id here
    NSDictionary *appParameters = @{SKStoreProductParameterITunesItemIdentifier :yourAppID};
    SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
    [productViewController setDelegate:self];
    [productViewController loadProductWithParameters:appParameters completionBlock:nil];
    [self presentViewController:productViewController animated:YES completion:nil];
}

Upvotes: 3

Related Questions