程序內(nèi)評(píng)價(jià)
在 iOS 10.3 中若贮,可以利用新的 API 在 App 內(nèi)通過彈窗的方式請(qǐng)求用戶直接給出評(píng)分斗遏,不再需要前往 App Store
蘋果在最新的iOS 10.3的SDK中的StoreKit框架中新增了一個(gè)類SKStoreReviewController來專門做這件事情掰邢,它只有一個(gè)類方法requestReview
[SKStoreReviewController requestReview]
顯示效果
考慮到兼容問題愧口,修改代碼如下:如下
Class clazz = NSClassFromString(@"SKStoreReviewController");
if(clazz != nil){
//iOS10.3 應(yīng)用內(nèi)打開
[SKStoreReviewController requestReview];
}else{
//跳轉(zhuǎn)到AppStore評(píng)論頁面
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; ```
有個(gè)細(xì)節(jié)大家需要注意在測(cè)試的時(shí)候發(fā)現(xiàn) “提交”按鈕不能用须鼎。[官方文檔描述](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上才能去評(píng)分修改
因此顯示效果是這樣的
![comment_appstore.png](http://upload-images.jianshu.io/upload_images/576060-ae86cfcac7c0f1ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##應(yīng)用內(nèi)修改修改App圖標(biāo)
####iOS10.3修改APP圖標(biāo)主要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手動(dòng)修改
![info.png](http://upload-images.jianshu.io/upload_images/576060-821546b0fdfedbfa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
####最后再代碼中實(shí)現(xiàn)切換icon
-(void)changeAppIconWithName:(NSString *)imageName{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.3.0")) {
if([[UIApplication sharedApplication] supportsAlternateIcons]){
NSLog(@"支持更換圖標(biāo)");
}else{
NSLog(@"不支持更換圖標(biāo)");
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)