您的位置:首页 > 移动开发

iOS跳转App Store应用评论页

2016-04-26 15:32 627 查看
在这里把应用中用到的跳转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上的项目代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: