如何使用 SKStoreReviewController java让用户输入数字给 App 评分

iOS 10.3 开始请求应用商店评分的正确姿势:SKStoreReviewController
iOS 10.3 开始请求应用商店评分的正确姿势:SKStoreReviewController
App 开发者的最主要目标之一就是获得更多曝光,并且从用户那里接收反馈从而改进 app,以便鼓励其他用户尝试使用。多年以来,开发者都在使用第三方方法来建议用户去商店打分,大部分是基于用户使用 app 的时长和频率。但使用这些第三方方法会导致体验不够理想。通常用户会被送到 AppStore app 来撰写评价,甚至用户还要手动选择“评论”标签页才能开始写评价。
在 iOS 10.3 的更新里,Apple 在 iOS 平台上做了几个重要改动,最受开发者欢迎的就是向用户询问评分的官方方式。所以从 10.3 开始,我们可以用 StoreKit 来询问用户评分,并且 StoreKit 会替我们处理剩下的工作。可以看
的文档。理论上来说,开发者只要加一行代码即可请求评分,但还有几点值得注意。
根据文档所述,请求评分函数使用了私有方法来分析当前是否是向用户询问评分的好时机,所以 Apple 强烈建议开发者不要在相应用户行为时调用此方法。例如,如果你把请求评分放在按钮触摸的回调函数里,但此时 iOS 可能决定不显示评分,所以用户就会认为 app 的功能出现了问题。另一方面,也不要太早让用户评分,最好等 app 运行几次之后再询问评分。尽管我们并不了解 Apple 的算法,但我们知道此方法的行为模式,所以最好在确定用户处于合适的时间时再进行询问。
注意:在开发时,所有评分请求都会通过,也就是说每次请求评分,评分对话框都会显示,但无法提交评分。在 Testflight 中,请求都不会被通过,所以如果 Testflight 测试时评分对话框没有正确显示,不要慌张。app 上架后,就会使用 Apple 方法在合适的时间显示对话框了。
不多说了,下面是用 Swift 实现请求评分的方式。
1. 首先,import StoreKit
import StoreKit
2. 现在就可以如下询问评分了
SKStoreReviewController.requestReview()
就这么简单!比想象中容易多了吧!
如果你想支持老的 iOS 版本,最好这么做:
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
// 退回老的版本
// 尝试手写或用第三方方法。
在我看来,实现 RequestReview 的正确姿势是:
在项目里创建新的 Swift 文件
导入所需框架
import Foundation
import StoreKit
定义设置变量
let runIncrementerSetting = "numberOfRuns"
// 用于存储运行次数的 UserDefauls 字典键
let minimumRunCount = 5 // 询问评分的最少运行次数
然后写一个运行计数器,功能就是在 UserDefaults 存储运行次数。此计数器需要两个函数。一个从 UserDefaults 里读取,另一个将其加一并存回 UserDefaults。
func incrementAppRuns() {
// app 运行次数计数器。可以在 App Delegate 中调用此方法
let usD = UserDefaults()
let runs = getRunCounts() + 1
usD.setValuesForKeys([runIncrementerSetting: runs])
usD.synchronize()
func getRunCounts () -& Int {
// 从 UserDefaults 里读取运行次数并返回。
let usD = UserDefaults()
let savedRuns = usD.value(forKey: runIncrementerSetting)
var runs = 0
if (savedRuns != nil) {
runs = savedRuns as! Int
print("已运行(runs)次")
return runs
下一步是用于请求评分的函数。我们需要在此函数里考虑两个因素。首先,是否有足够的运行次数来询问评分。其次,检查是否是 iOS10.3 及以上版本,这样我们才能调用此函数。
func showReview() {
let runs = getRunCounts()
print("显示评分")
if (runs & minimumRunCount) {
if #available(iOS 10.3, *) {
print("已请求评分")
SKStoreReviewController.requestReview()
// 回到老版本
print("请求评分所需的运行次数不足!")
下一步就是从 App Delegate 里调用运行计数器。所以在 app 的 didFinishLaunchingWithOptions 函数里添加如下内容:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -& Bool {
incrementAppRuns()
return true
最后一步是在合适的时间里调用 showReview()。我的建议是在用户完成 app 中某项主要工作后调用此函数。例如你在开发游戏,向用户展示分数时就可以调用此函数。记住如果要把它放在按钮回调里,就要和其它任务一起才行。例如,在 Shuffle 里面,我把 showReview() 函数放在壁纸的下载按钮中。所以用户下载完壁纸后,如果 requestReview 决定显示评分,就会显示在下载完成的壁纸上。这样就可以确保按钮总是能够正确工作,同时还能确保用户在 app 中完成主要任务时可以显示请求评分页面。
showReview()
好啦!现在可以运行你的 app 来看看效果。
需要的话,可以从 GitHub 上下载我的脚本,包含了此教程中的 1-5 步。
欢迎在下面评论。编程愉快!
作者:张嘉夫
链接:/p/adee28dcfe09
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
PHP开发框架
开发工具/编程工具
服务器环境Xcode 8.3 (iOS 10.3)新增应用内评价API 之 SKStoreReviewController_iOS开发_动态网站制作指南
Xcode 8.3 (iOS 10.3)新增应用内评价API 之 SKStoreReviewController
来源:人气:776
Allow Users to ovide Ratings From Within Your App
在iOS 10.3之后,系统提供了一个SKStoreReviewController类,可以帮助在app内部实现评价。App实现评价的调用方式如下:
调用方式:
[SKStoreReviewController requestReview];
官方注解讨论
Although you should call this method when it makes sense in the user experience flow of your app, the actual display of a rating/review request view is governed by App Store policy. Because this method may or may not present an alert, it’s not appropriate to call it in response to a button tap or other user action.
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.
When you call this method in your shping app and a rating/review request view is displayed, the system handles the entire process for you. In addition, you can continue to include a persistent link in the settings or configuration screens of your app that deep-links to your App Store product page. To automatically open a page on which users can write a review in the App Store, append the query parameter action=write-review to your product URL.
苹果官方API链接:
/reference/storekit/skstorereviewcontroller/2851536-requestreview?language=objc
优质网站模板iOS应用内打开App Store应用详情界面
& & 用iPhone浏览UC的&应用商店&时,发现可以直接在应用内打开App Store中的应用详情和下载页面。效果如下:
& & & & 下面来看看怎么实现这个效果吧。
& & & & 苹果官方文档 &SKStoreProductViewController Class Reference&里有如下介绍:
A SKStoreProductViewController object presents a store that allows the user to purchase other media from the App Store. For example, your app might display the store to allow the user to purchase another app. &
To display a store, create a new SKStoreProductViewController object and set its delegate. Then, present the view controller modally from another view controller in your app. Your delegate dismisses the view controller when the user completes the purchase. &
To choose a specific product, call the loadProductWithParameters:completionBlock: method, passing the iTunes item identifier for the item you want to sell. &
& & & & 由上可知,通过Modal view方式弹出App Store商品详情页面。我按照文档说明,写了个例子。部分代码如下:
- (void)openAppWithIdentifier:(NSString *)appId { &
& & SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init]; &
& & storeProductVC.delegate = &
& & NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier]; &
& & [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError *error) { &
& & & & if (result) { &
& & & & & & [self presentViewController:storeProductVC animated:YES completion:nil]; &
& & & & } &
另外,需要实现SKStoreProductViewControllerDelegate如下代理方法:
#pragma mark - SKStoreProductViewControllerDelegate &
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController { &
& & [viewController dismissViewControllerAnimated:YES completion:^{ &
& & & & [viewController release]; &
可以这样调用:
[self openAppWithIdentifier:@&&]; &
这段代码即实现了上面图示的效果。
注:项目需要添加StoreKit框架,仅在iOS 6.0以上的设备中支持上述实现。
Framework & &&
/System/Library/Frameworks/StoreKit.framework &
Availability & & &
Available in iOS 6.0 and later. &
如果需要兼容6.0以下的设备,可以使用下面的代码(这种方式会跳出当前应用):
- (void)outerOpenAppWithIdentifier:(NSString *)appId { &
& & NSString *urlStr = [NSString stringWithFormat:@&itms-apps:///us/app/id%@?mt=8&, appId]; &
& & NSURL *url = [NSURL URLWithString:urlStr]; &
& & [[UIApplication sharedApplication] openURL:url]; &

我要回帖

更多关于 如何让用户关注公众号 的文章

 

随机推荐