Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

xcode - Appstore as modal view in iOS6

I noticed that when the user taps an app store link in the iOS6 mail app, mail opens a modal view representing the app store instead of switching to the App Store app as it did in previous versions.

Does Apple provide access to this capability, or it is exclusive to their integrated programs?


Note: If you have iOS 6 and want test it, just open appstore and email app to yourself.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I added this method as a category to UIViewController, but you can repurpose it for your own needs. The app store ID is the big number in the app store URL. Make sure you import the StoreKit framework and header file!

@import StoreKit;

- (void)presentAppStoreForID:(NSNumber *)appStoreID withDelegate:(id<SKStoreProductViewControllerDelegate>)delegate
{
    if(NSClassFromString(@"SKStoreProductViewController")) { // Checks for iOS 6 feature.

        SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
        storeController.delegate = delegate; // productViewControllerDidFinish

        // Example App Store ID (e.g. for Words With Friends)
        // @322852954

        [storeController loadProductWithParameters:@{ SKStoreProductParameterITunesItemIdentifier: appStoreID }
                                   completionBlock:^(BOOL result, NSError *error) {
            if (result) {
                [self presentViewController:storeController animated:YES completion:nil];
            } else {
                [[[UIAlertView alloc] initWithTitle:@"Uh oh!" message:@"There was a problem opening the app store" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil] show];
            }
        }];

    } else { // Before iOS 6, we can only open the App Store URL
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",appStoreID]]];
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...