ios6之后墨辛,SKStoreProductViewController的出現(xiàn),成功解決了在app內(nèi)推廣另一個app的方法奏赘。實現(xiàn)方法如下
1.在類內(nèi)導(dǎo)入<StoreKit/StoreKit.h>頭文件太惠,并繼承SKStoreProductViewControllerDelegate代理。
2.點擊出現(xiàn)另一個app的官方頁面凿渊,不需要跳轉(zhuǎn)到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.實現(xiàn)代理方法埃脏。(取消時能回到自己的app頁面)
#pragma mark - SKStoreProductViewControllerDelegate
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:^{
}];
}