2

In iOS app, Anytime I call this function to open app store,

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://app-url"]];


The Original app will be deactivated. The user will then have to restart the original app after they exit the App Store. It’s very inconvenient way of installation.

Is there any way to open App Store links without leaving the app?


For example, opened as popup window, after installation just close the popup window, and I can see the original app.


Updated :

I found a great example! Like this game's popup.

open app store as in app popup, example

2 Answers 2

6

Yes, we can open an App store link without leaving the existing app in IOS 6+. you can use below for it.

 #import <StoreKit/StoreKit.h>
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
    storeController.delegate = delegate;
    NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : appStoreID };
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
//Handle response
}

Thanks

2
  • 1
    Thanks that is what I want! And Maybe it'll be better answer if you add this code. [self presentViewController:storeController animated:YES completion:nil]; // ^^;
    – Jinbom Heo
    Mar 4, 2014 at 7:20
  • Block is depends on needs if you do not want then you can use nil. Can you +1 it and approve my answer?
    – Hindu
    Mar 4, 2014 at 7:25
1

My version is here.

1) #import <StoreKit/StoreKit.h> and set SKStoreProductViewControllerDelegate
2) add delegate response method,

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
    // if user do cancel, close it
    [viewController dismissViewControllerAnimated:YES completion:nil];
}

3) add store open code.

void SomeClassName::openAppStore(string appStoreId, string appUrl)
{
    // below iOS 6.0
    NSString *appUrlStatic = [NSString stringWithUTF8String:appUrl.c_str()];

    // iOS 6.0 or above, appstore id is 9-digin number
    NSString *appId = [NSString stringWithUTF8String:appStoreId.c_str()];;

    // check SKStoreProductViewController API exist or not
    if(NSClassFromString(@"SKStoreProductViewController")) {

        SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
        storeController.delegate = self;

        NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : appId };

        [storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
            if (result) {
                [self presentViewController:storeController animated:YES completion:nil];
            } else {
                [[[UIAlertView alloc] initWithTitle:@"Error Occur"
                                            message:@"Error to open App Store."
                                           delegate:nil
                                  cancelButtonTitle:@"Ok"
                                  otherButtonTitles: nil] show];
            }
        }];

        [storeController release];

    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appUrlStatic]];
    }


}

Your Answer

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

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