ios 跳轉AppStore的兩種方法,應用內和直接跳轉

jopen 8年前發布 | 65K 次閱讀 iOS開發 移動開發

#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]; }</pre>


來自: http://my.oschina.net/u/2365185/blog/597103

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!