1,导入framework StoreKit.framework
2, 在需要的跳转的类中导入 #import <StoreKit/StoreKit.h>
3,实现协议
@interface ViewController ()<SKStoreProductViewControllerDelegate>
- (void)showAppInApp:(NSString *)_appId {
Class isAllow = NSClassFromString(@"SKStoreProductViewController");
if (isAllow != nil) {
SKStoreProductViewController *sKStoreProductViewController = [[SKStoreProductViewController alloc] init];
sKStoreProductViewController.delegate = self;
[self presentViewController:sKStoreProductViewController
animated:YES
completion:nil];
[sKStoreProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: _appId}completionBlock:^(BOOL result, NSError *error) {
if (error) {
NSLog(@"%@",error);
}
}];
}
else{
//低于iOS6没有这个类
NSString *string = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/us/app/id%@?mt=8",_appId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}
#pragma mark - SKStoreProductViewControllerDelegate
//对视图消失的处理
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
}
注意要在真机下运行才有效果,模拟器打不开,报这个错误 Cannot connect to iTunes Store。
参考文章:
http://www.cnblogs.com/superhappy/archive/2013/05/09/3069210.html