清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#import "ViewController.h" #import <StoreKit/StoreKit.h> @interface ViewController ()<SKStoreProductViewControllerDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //第一种方法 直接跳转 UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 50)]; btn.backgroundColor = [UIColor redColor]; [btn setTitle:@"直接跳转" forState:UIControlStateNormal]; btn.tag = 1; [btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside]; //第二中方法 应用内跳转 UIButton *btnT = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)]; btnT.backgroundColor = [UIColor purpleColor]; btnT.tag = 2; [btnT setTitle:@"应用内跳转" forState:UIControlStateNormal]; [btnT addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; [self.view addSubview:btnT]; } - (void)btn:(UIButton *)btn{ if (btn.tag == 1) { //第一种方法 直接跳转 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id1018221712"]]; }else{ //第二中方法 应用内跳转 //1:导入StoreKit.framework,控制器里面添加框架#import <StoreKit/StoreKit.h> //2:实现代理SKStoreProductViewControllerDelegate SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init]; storeProductViewContorller.delegate = self; // ViewController *viewc = [[ViewController alloc]init]; // __weak typeof(viewc) weakViewController = viewc; //加载一个新的视图展示 [storeProductViewContorller loadProductWithParameters: //appId @{SKStoreProductParameterITunesItemIdentifier : @"1018221712"} completionBlock:^(BOOL result, NSError *error) { //回调 if(error){ NSLog(@"错误%@",error); }else{ //AS应用界面 [self presentViewController:storeProductViewContorller animated:YES completion:nil]; } }]; } } #pragma mark - 评分取消按钮监听 //取消按钮监听 - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{ [self dismissViewControllerAnimated:YES completion:nil]; }