ios 实现跳转到评价界面的两种方式

要想在App内跳转到特定App的详情页或者评论页,首先需要获取到App的id。在 iTunes Connect网站上登陆之后,选择“我的App”,然后点击某个特定的App进入,在App信息的综合信息中,会有一个“Apple ID”的条目,就是一串数字,这个就是对应App的id了。另外在App信息的额外信息中, 点击“在 App Store 中查看”会跳转到一个特定链接的页面,这个链接在下文中也会用到,这个链接会大概是这样的"https://itunes.apple.com/us /app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"。

一、iOS应用内跳转到App Store详情页有两种方式:

1、跳转到App Store应用中对应App的详情页

 
(1)直接使用上文中获取到的链接,通过openURL方法实现,即
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"https://itunes.apple.com/us/app/fa-bu-ce-shi/idxxxxxxxxx?l=zh&ls=1&mt=8"]];
将上述链接中的https://更换为itms://或者itms-apps://也可以实现跳转效果,但itms://开头的链接是跳转到iTunes Store应用中,https://与itms-apps://开头的链接是跳转到App Store应用中。
 
(2)利用上文获取到的appId拼接成链接“itms-apps://itunes.apple.com/app/idxxxxxxxxx”,也通过openURL方法实现,即
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/app/idxxxxxxxxx"]];
 
2、在App内部跳转到指定App详情页

步骤为:

(1)导入相应的框架
#import <StoreKit/StoreKit.h>
(2)使当前控制器遵守协议SKStoreProductViewControllerDelegate
(3)在应当跳转方法中实现下列代码,即创建SKStoreProductViewController控制器,设置代理,加载相应内容,在加载完成的回调中,等加载完成之后使用present的方式将视图控制器呈现出来。
 
    SKStoreProductViewController *storeProductVC = [[SKStoreProductViewControlleralloc]init];
    storeProductVC.delegate = self;
 
    [storeProductVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@xxxxxxxxx}completionBlock:^(BOOL result, NSError * _Nullable error) {
        if (error) {
            NSLog(@"%@",[error localizedDescription]);
        } else {
            NSLog(@"加载完成");
            [selfpresentViewController:storeProductVC animated:YEScompletion:^{
                NSLog(@"界面弹出完成");
            }];
        }
    }];
 
(4)实现SKStoreProductViewControllerDelegate的代理方法,即
 
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
    NSLog(@"用户请求页面弹回");
    [selfdismissViewControllerAnimated:YEScompletion:^{
        NSLog(@"页面弹回完成");
    }];
}
 
当用户点击取消时,会执行此代理方法,将控制器弹回即可。
 
 二、iOS应用内跳转到App Store评论页有iOS7之前和之后的区别:跳转方法一样,但是链接不同,即
 
(1)iOS7之前
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxxxxx"]];//iOS7之前跳转到App评论页
 
(2)iOS7之后
    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=xxxxxxxxx&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];//iOS7之后跳转到App评论页
 
转自:http://blog.csdn.net/u012894479/article/details/50737365
posted @ 2016-09-18 15:33  码锋窝  阅读(2498)  评论(0编辑  收藏  举报