iOS跳转App Store应用评论页

在这里把应用中用到的跳转App Store应用评论页的代码备份一下,之后应用不再支持iOS 7了,删掉之后担心再找不到。

首先iOS 7以下的版本、iOS 7和iOS 8+的跳转URL是不同的,所以必须区别处理,以下是代码逻辑:

这里先定义一个模板,根据不同的系统版本做处理,可以看到URL是不一样的

static NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";  
static NSString *templateReviewURLiOS7 = @"itms-apps://itunes.apple.com/app/idAPP_ID";  
static NSString *templateReviewURLiOS8 = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=APP_ID&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software";  

然后根据不同的系统版本做判断,将应用的appID替换模板中的APP_ID,最后调用系统接口打开URL就可以了

NSString *reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%@", appID]];  
// iOS 7 needs a different templateReviewURL @see https://github.com/arashpayan/appirater/issues/131  
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.1) {  
    reviewURL = [templateReviewURLiOS7 stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%@", appID]];  
}  
// iOS 8 needs a different templateReviewURL also @see https://github.com/arashpayan/appirater/issues/182  
else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {  
    reviewURL = [templateReviewURLiOS8 stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%@", appID]];  
}  
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:reviewURL]]) {  
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]];  
}  

可以参看一下注释中提到的github上的项目代码。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,976评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,198评论 4 61
  • 光阴清冷,握字为暖,剪诗为妆,素梦安然。杯盘茶盏,烟波轻卷,日月昭华,浅呓深谙。
    柒大小姐阅读 308评论 0 1
  • 初春的阳光诈暖还寒,从炎热的夏天喜欢一个人到初春的时光,那是多么漫长而煎熬的日子。我和你,一步之遥;我既无法上前一...
    summer_5650阅读 140评论 1 2
  • 孩子,我允许你不优秀,但不允许你没教养!建议家长看看! 一个孩子的教养是成功的基本因素,而教养是从小就要开始培养的...
    滴答的钟声阅读 451评论 4 3