1、导入framework
#import <StoreKit/StoreKit.h>
2、监听取消键的点击需要遵守协议
@interface ViewController () <SKStoreProductViewControllerDelegate>
3、配置SKStoreProductViewController
SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init];
storeProductVC.delegate = self;
NSDictionary *dic = [NSDictionary dictionaryWithObject:APPID forKey:SKStoreProductParameterITunesItemIdentifier];
[storeProductVC loadProductWithParameters:dic completionBlock:^(BOOL result, NSError * _Nullable error) {
if (!error) {
[self presentViewController:storeProductVC animated:YES completion:nil];
} else {
NSLog(@"ERROR:%@",error);
}
}];
4、实现代理方法,点击取消键Appstore隐藏
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:nil];
}
注:这里的APPID就是app在Appstore的一串数字编号
#define APPID @"952950430"
最终效果就不截图了,就是在类似广告的那种,在应用中弹出Appstore。使用的时候用真机调试。