Jinbom Heo
Jinbom Heo

Reputation: 7400

Open App Store links without leaving the app, possible?

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

Upvotes: 2

Views: 848

Answers (2)

Jinbom Heo
Jinbom Heo

Reputation: 7400

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]];
    }


}

Upvotes: 1

Hindu
Hindu

Reputation: 2924

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

Upvotes: 6

Related Questions