由於項目有需求在應用內引導評分功能,新手記錄開發過程。
iOS引導評分有三種方式:
詳見以下博客地址,這位大佬總結的非常到位:https://blog.csdn.net/jiadabin/article/details/78473927
簡述如下:
1、跳轉Appstore
可以跳轉到App Store評分頁面,同時評分及寫評論。
2、在自已的應用內打開評分彈框(iOS10.3之後)
不能寫評論,一年一臺設備中只能彈出3次。
3、在應用內部加載appstore。
以下是項目中採用的方式,自定義彈框,採用跳轉appstore方法。彈窗使用UIAlertController
,風格使用UIAlertControllerStyleAlert
,如下:
UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:content, nil) preferredStyle:UIAlertControllerStyleAlert];
在UIAlertController
添加需要的操作,比如好評、差評、以後再說。代碼如下:
UIAlertAction *laterAction = [UIAlertAction actionWithTitle:@"later" , nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// later -- dismiss dialog
}];
跳轉商店評分使用 UIApplication openURL 的方式跳轉,App Store相關URL如下:
1.跳轉商店內應用首頁
itms-apps://itunes.apple.com/app/idxxxxxxxx
或
http://itunes.apple.com/app/idxxxxxxxx
2.跳轉商店內應用評論頁面
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&id=xxxxxxxx
或
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&id=xxxxxxxx
參數含義如下:
type:
onlyLatestVersion: 只顯示關於最新版本的評論
pageNumber:
sortOrdering:排序方式
id: xxxxxxxx爲app的appleID
也可以直接不帶以上參數,只帶appleid ,appleid在iTunes connet上找,並不能通過代碼動態獲取。
出現問題:
1、跳轉到App Store時“沒有連接到App Store”。
**原因:**iOS11 系統之後跳轉商店評分地址有些許改變,對系統做出判斷,使用不同的連接地址即可。 代碼如下:
+(void)skipAppStore:(NSString *)appAppleId{
NSString *urlStr;
if (@available(iOS 11.0,*)) {
urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8&action=write-review",appAppleId];
}else{
urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8",appAppleId];
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
題外話:
iOS可以通過appleID調用蘋果search API 獲取應用相關信息,比如應用詳情頁的圖片、版本號、應用名稱等等。可以參考蘋果官網地址:https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html