ios6之后,SKStoreProductViewController的出现,成功解决了在app内推广另一个app的方法。实现方法如下
1.在类内导入<StoreKit/StoreKit.h>头文件,并继承SKStoreProductViewControllerDelegate代理。
2.点击出现另一个app的官方页面,不需要跳转到appStore的方法
- (void)showOtherAppVC {
Class isAllow = NSClassFromString(@"SKStoreProductViewController");
if (isAllow == nil)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:AppStoreAddress]];
return;
}
NSDictionary *param = @{SKStoreProductParameterITunesItemIdentifier:@"688052810"};(填写其他app的appId)
SKStoreProductViewController *vc = [[SKStoreProductViewController alloc]init];
vc.delegate = self;
[vc loadProductWithParameters:param completionBlock:^(BOOL result, NSError * _Nullable error) {
if (result)
{
[self presentViewController:vc animated:YES completion:NULL];
}
else
{
NSLog(@"error:%@",error);
}
}];
3.实现代理方法。(取消时能回到自己的app页面)
#pragma mark - SKStoreProductViewControllerDelegate
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:^{
}];
}