1、导入framework#import
#import <StoreKit/StoreKit.h>
2、遵守协议,实现代理方法
@interface ViewController ()<SKStoreProductViewControllerDelegate>
/// 取消按钮点击
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:nil];
}
3、配置SKStoreProductViewController
NSString *APPID = @"app唯一标识";
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);
}
}];