1,导入#StoreKit/StoreKit.h 库
#import <StoreKit/StoreKit.h>
2,遵守SKStoreProductViewControllerDelegate协议
3,使用如下代码 其中900089067为app在App Store中的id号
SKStoreProductViewController *store = [[SKStoreProductViewController alloc] init];
store.delegate = self;
NSDictionary *dic = [NSDictionary dictionaryWithObject:@"900089067" forKey:SKStoreProductParameterITunesItemIdentifier];
[store loadProductWithParameters:dic completionBlock:^(BOOL result, NSError * _Nullable error) {
if (!error) {
[self presentViewController:store animated:YES completion:nil];
}
else {
NSLog(@"ERROR:%@", error);
}
}];
4实现代理
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[viewController dismissViewControllerAnimated:YES completion:nil];
}
完美成功