由于项目有需求在应用内引导评分功能,新手记录开发过程。
iOS引导评分有三种方式:
详见以下博客地址,这位大佬总结的非常到位:https://blog.youkuaiyun.com/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