iOS6以后,苹果提供了在应用内部打开App Store中某一个应用下载页面的方式,提供了 SKStoreProductViewController类进行支持
1、添加 #import
2、添加代理 SKStoreProductViewControllerDelegate
3、添加代码
- (void)evaluate
{
Class isAllow = NSClassFromString(@"SKStoreProductViewController");
if (isAllow != nil && ![[UIDevice currentDevice].model isEqualToString:@"iPhone Simulator"])
{
[self showLoadingView];
__weak __typeof(self) weakself = self;
SKStoreProductViewController *product = [[SKStoreProductViewController alloc] init];
product.delegate = self;
[product loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"APP ID"} completionBlock:^(BOOL result, NSError *error) {
__strong __typeof(weakself) strongself = weakself;
[strongself hideLoadingView];
if (error) {
NSLog(@"error = %@ with userinfo = %@",error,[error userInfo]);
} else {
[strongself presentViewController:product animated:YES completion:nil];
}
}];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];
}
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
网友评论