程序内评价
在 iOS 10.3 中,可以利用新的 API 在 App 内通过弹窗的方式请求用户直接给出评分,不再需要前往 App Store
苹果在最新的iOS 10.3的SDK中的StoreKit框架中新增了一个类SKStoreReviewController来专门做这件事情,它只有一个类方法requestReview
[SKStoreReviewController requestReview]
显示效果
考虑到兼容问题,修改代码如下:如下
Class clazz = NSClassFromString(@"SKStoreReviewController");
if(clazz != nil){
//iOS10.3 应用内打开
[SKStoreReviewController requestReview];
}else{
//跳转到AppStore评论页面
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review", appId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
}
苹果官方API描述
/** Request StoreKit to ask the user for an app review. This may or may not show any UI.
*
* Given this may not succussfully present an alert to the user, it is not appropriate for use
* from a button or any other user action. For presenting a write review form, a deep link is
* available to the App Store by appending the query params "action=write-review" to a product URL.
*/
+ (void)requestReview; ```
有个细节大家需要注意在测试的时候发现 “提交”按钮不能用。[官方文档描述](https://developer.apple.com/reference/storekit/skstorereviewcontroller/2851536-requestreview)
```"When you call this method while your app is still in development mode, a rating/review request view is always displayed so that you can test the user interface and experience. However, this method has no effect when you call it in an app that you distribute using TestFlight."```
就是只有在testFlight上才能去评分修改
因此显示效果是这样的
![comment_appstore.png](http://upload-images.jianshu.io/upload_images/576060-ae86cfcac7c0f1ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##应用内修改修改App图标
####iOS10.3修改APP图标主要Api为:
- (void)setAlternateIconName:(nullable NSString *)alternateIconName completionHandler:(nullable void (^)(NSError *_Nullable error))completionHandler
####除了使用此方法外,还需要在Info.plist中添加配置,[配置说明](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW14)
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/576060-4fa7da886ce9830f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##### info.plist直接添加源代码方式
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>new_icon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>new_icon</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>Icon-60</string>
</array>
</dict>
</dict>
##### info.plist手动修改
![info.png](http://upload-images.jianshu.io/upload_images/576060-821546b0fdfedbfa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
####最后再代码中实现切换icon
-(void)changeAppIconWithName:(NSString *)imageName{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3.0")) {
if([[UIApplication sharedApplication] supportsAlternateIcons]){
NSLog(@"支持更换图标");
}else{
NSLog(@"不支持更换图标");
return;
}
NSString *alternateIconName = [UIApplication sharedApplication].alternateIconName;
if(alternateIconName == nil){
[[UIApplication sharedApplication] setAlternateIconName:imageName completionHandler:^(NSError * _Nullable error) {
if(error){
NSLog(@"%@",error);
}
}];
}
}
}
####显示效果
改变后提示效果
![change.png](http://upload-images.jianshu.io/upload_images/576060-97ef726f788b4c85.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
icon显示效果
![chang_icon.png](http://upload-images.jianshu.io/upload_images/576060-5b5becdb9ce8388c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)