Search code examples
iosobjective-cmodalviewcontrolleritunes-store

iTunes Store as Modal view


I would like to open some iTunes song's link in my app, but I don't want to redirect from my app to app store. I would like to open iTunes Store as a modal view like Facebook do it when you press on a sponsored app. How can I do it? ( in "home made" modal view with web view?? I hope not )

For example how to open this link as a modal view, and user can buy right there: @"https://itunes.apple.com/us/album/how-i-feel/id731197191?i=731197197&ign-mpt=uo%3D4"

Right now I'm using this:

[[UIApplication sharedApplication]
 openURL:[NSURL URLWithString:@"itms://itunes.apple.com/us/album/how-i-feel/id731197191?i=731197197&uo=4"]];

Of course it won't open in a modal view.


Solution

  • Ok, so I' ve solved my problem, and I won't delete my question, because I didn't find it in stack overflow :

    SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
    
    [storeProductViewController setDelegate:self];
    [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @"731197191"} 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];
        }
    }];