在這里把應(yīng)用中用到的跳轉(zhuǎn)App Store應(yīng)用評論頁的代碼備份一下螟炫,之后應(yīng)用不再支持iOS 7了波附,刪掉之后擔(dān)心再找不到艺晴。
首先iOS 7以下的版本昼钻、iOS 7和iOS 8+的跳轉(zhuǎn)URL是不同的,所以必須區(qū)別處理封寞,以下是代碼邏輯:
這里先定義一個模板然评,根據(jù)不同的系統(tǒng)版本做處理,可以看到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";
然后根據(jù)不同的系統(tǒng)版本做判斷狈究,將應(yīng)用的appID替換模板中的APP_ID碗淌,最后調(diào)用系統(tǒng)接口打開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上的項目代碼。