美文网首页
iOS-应用直接跳转到App Store

iOS-应用直接跳转到App Store

作者: Mr_Bob_ | 来源:发表于2016-06-12 11:08 被阅读7767次
前言:

目前很多应用是要求点击事件直接跳转到App Store,目前是有两种方法实现跳转:一种是直接通过openURL:的方法跳转进入,另一种是通过苹果自身的SKStoreProductViewController 该控制器去实现,他们之前的区别是,前者直接跳转到appStore,后者则在应用内打开.

方法一:(利用url跳转)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/shan-shan-pen-di-fu-nu-jian/id1049660516?mt=8"]];
方法二:

应用内直接跳转到appstore,需要添加StoreKit,framework系统库,需要实现下面的代理方法

SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewControlleralloc] init];
//设置代理请求为当前控制器本身
storeProductViewContorller.delegate = self;
//加载一个新的视图展示
[storeProductViewContorller loadProductWithParameters:
 //appId唯一的
 @{SKStoreProductParameterITunesItemIdentifier : @"1049660516"} completionBlock:^(BOOL result, NSError *error) {
     //block回调
     if(error){
         NSLog(@"error %@ with userInfo %@",error,[error userInfo]);
     }else{
         //模态弹出appstore
         [self presentViewController:storeProductViewContorller animated:YES completion:^{
             
         }
          ];
     }
 }]

//取消按钮监听
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

相关文章

网友评论

      本文标题:iOS-应用直接跳转到App Store

      本文链接:https://www.haomeiwen.com/subject/rwuedttx.html