如何使用requestReview (SKStore Review Controller) 在随机时间段后在当前 viewController 显示评论弹出窗口
How to use requestReview (SKStoreReviewController) to show review popup in the current viewController after a random period of time
我已经阅读了 iOS 10.3 中提供的这项新功能,并认为它会更加灵活且开箱即用。但是在我阅读 docs 之后,我发现您需要决定显示它的时间以及调用它的 viewController 。有什么方法可以让它在随机时间段后触发,当时显示任何 viewController 吗?
在您的 AppDelegate 中:
Swift:
import StoreKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let shortestTime: UInt32 = 50
let longestTime: UInt32 = 500
guard let timeInterval = TimeInterval(exactly: arc4random_uniform(longestTime - shortestTime) + shortestTime) else { return true }
Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(AppDelegate.requestReview), userInfo: nil, repeats: false)
}
@objc func requestReview() {
SKStoreReviewController.requestReview()
}
Objective-C:
#import <StoreKit/StoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
int shortestTime = 50;
int longestTime = 500;
int timeInterval = arc4random_uniform(longestTime - shortestTime) + shortestTime;
[NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(requestReview) userInfo:nil repeats:NO];
}
- (void)requestReview {
[SKStoreReviewController requestReview];
}
上面的代码将要求 Apple 在应用程序完成启动后 50 到 500 秒之间的随机时间提示用户对应用程序进行评分。
请记住,根据 Apple 的文档,无法保证在调用 requestReview 时会出现评级提示。
对于Objective - C:
添加StoreKit.framework
然后在你的 viewController.h
#import <StoreKit/StoreKit.h>
然后在你的函数调用中:
[SKStoreReviewController requestReview];
对于Swift
添加StoreKit.framework
在你的ViewController.swift
import StoreKit
然后在你的函数调用中:
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
// Open App Store with OpenURL method
}
就是这样! Apple 会自行决定何时显示评分(随机)。
在开发中,每次调用它都会被调用。
已编辑:无需检查 OS 版本,如果 OS 小于 10.3,StoreKit 将不会弹出,谢谢 Zakaria。
随机弹出不是使用该例程的好方法,不仅违反了 Apple 的建议,而且会给您带来不太好的结果。
用随机的弹出窗口来烦扰用户永远不会像在适当的时间提示他们那样成功——比如当他们刚刚完成一个级别或创建一个文档时,并且有那种温暖的模糊感觉成就。
我还不能添加评论,但如果您使用的是 Appirater,您可能需要检查版本以查看其是否低于 10.3,以便弹出另一个 Appirater 评论消息框。
听取了 Peter Johnson 的建议,我创建了一个简单的 class,您只需将方法粘贴到代码中所需的位置,它就会在用户刚刚成功的位置弹出.
struct DefaultKeys {
static let uses = "uses"
}
class ReviewUtility {
// Default Keys stored in Structs.swift
static let sharedInstance = ReviewUtility()
private init() {}
func recordLaunch() {
let defaults = UserDefaults.standard
// if there's no value set when the app launches, create one
guard defaults.value(forKey: DefaultKeys.uses) != nil else { defaults.set(1, forKey: DefaultKeys.uses); return }
// read the value
var totalLaunches: Int = defaults.value(forKey: DefaultKeys.uses) as! Int
// increment it
totalLaunches += 1
// write the new value
UserDefaults.standard.set(totalLaunches, forKey: DefaultKeys.uses)
// pick whatever interval you want
if totalLaunches % 20 == 0 {
// not sure if necessary, but being neurotic
if #available(iOS 10.3, *) {
// do storekit review here
SKStoreReviewController.requestReview()
}
}
}
}
要使用它,请将其粘贴在您希望它被调用的位置,希望您不会随意勾选用户。
ReviewUtility.sharedInstance.recordLaunch()
随机显示对话框可能不是一个好主意。请参阅 Apple guideline,其中提到:不要打扰用户,尤其是当他们正在执行 time-sensitive 或有压力的任务时。
这是 Apple 的建议:
仅在用户表现出对您的应用的参与度后才要求评分。例如,在 完成游戏级别 或 生产力任务 时提示用户。切勿在首次发布或入职期间要求评级。留出足够的时间来形成意见。
不要成为害虫。重复的评分提示可能会令人恼火,甚至可能会对用户对您应用的看法产生负面影响。允许 至少 间隔一两周的评分请求,并且仅在用户表现出对您的应用的更多参与度后再次提示。
这个post也蛮有意思的...
我已经阅读了 iOS 10.3 中提供的这项新功能,并认为它会更加灵活且开箱即用。但是在我阅读 docs 之后,我发现您需要决定显示它的时间以及调用它的 viewController 。有什么方法可以让它在随机时间段后触发,当时显示任何 viewController 吗?
在您的 AppDelegate 中:
Swift:
import StoreKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let shortestTime: UInt32 = 50
let longestTime: UInt32 = 500
guard let timeInterval = TimeInterval(exactly: arc4random_uniform(longestTime - shortestTime) + shortestTime) else { return true }
Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(AppDelegate.requestReview), userInfo: nil, repeats: false)
}
@objc func requestReview() {
SKStoreReviewController.requestReview()
}
Objective-C:
#import <StoreKit/StoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
int shortestTime = 50;
int longestTime = 500;
int timeInterval = arc4random_uniform(longestTime - shortestTime) + shortestTime;
[NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(requestReview) userInfo:nil repeats:NO];
}
- (void)requestReview {
[SKStoreReviewController requestReview];
}
上面的代码将要求 Apple 在应用程序完成启动后 50 到 500 秒之间的随机时间提示用户对应用程序进行评分。 请记住,根据 Apple 的文档,无法保证在调用 requestReview 时会出现评级提示。
对于Objective - C:
添加StoreKit.framework
然后在你的 viewController.h
#import <StoreKit/StoreKit.h>
然后在你的函数调用中:
[SKStoreReviewController requestReview];
对于Swift
添加StoreKit.framework
在你的ViewController.swift
import StoreKit
然后在你的函数调用中:
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
// Open App Store with OpenURL method
}
就是这样! Apple 会自行决定何时显示评分(随机)。 在开发中,每次调用它都会被调用。
已编辑:无需检查 OS 版本,如果 OS 小于 10.3,StoreKit 将不会弹出,谢谢 Zakaria。
随机弹出不是使用该例程的好方法,不仅违反了 Apple 的建议,而且会给您带来不太好的结果。
用随机的弹出窗口来烦扰用户永远不会像在适当的时间提示他们那样成功——比如当他们刚刚完成一个级别或创建一个文档时,并且有那种温暖的模糊感觉成就。
我还不能添加评论,但如果您使用的是 Appirater,您可能需要检查版本以查看其是否低于 10.3,以便弹出另一个 Appirater 评论消息框。
听取了 Peter Johnson 的建议,我创建了一个简单的 class,您只需将方法粘贴到代码中所需的位置,它就会在用户刚刚成功的位置弹出.
struct DefaultKeys {
static let uses = "uses"
}
class ReviewUtility {
// Default Keys stored in Structs.swift
static let sharedInstance = ReviewUtility()
private init() {}
func recordLaunch() {
let defaults = UserDefaults.standard
// if there's no value set when the app launches, create one
guard defaults.value(forKey: DefaultKeys.uses) != nil else { defaults.set(1, forKey: DefaultKeys.uses); return }
// read the value
var totalLaunches: Int = defaults.value(forKey: DefaultKeys.uses) as! Int
// increment it
totalLaunches += 1
// write the new value
UserDefaults.standard.set(totalLaunches, forKey: DefaultKeys.uses)
// pick whatever interval you want
if totalLaunches % 20 == 0 {
// not sure if necessary, but being neurotic
if #available(iOS 10.3, *) {
// do storekit review here
SKStoreReviewController.requestReview()
}
}
}
}
要使用它,请将其粘贴在您希望它被调用的位置,希望您不会随意勾选用户。
ReviewUtility.sharedInstance.recordLaunch()
随机显示对话框可能不是一个好主意。请参阅 Apple guideline,其中提到:不要打扰用户,尤其是当他们正在执行 time-sensitive 或有压力的任务时。
这是 Apple 的建议:
仅在用户表现出对您的应用的参与度后才要求评分。例如,在 完成游戏级别 或 生产力任务 时提示用户。切勿在首次发布或入职期间要求评级。留出足够的时间来形成意见。
不要成为害虫。重复的评分提示可能会令人恼火,甚至可能会对用户对您应用的看法产生负面影响。允许 至少 间隔一两周的评分请求,并且仅在用户表现出对您的应用的更多参与度后再次提示。
这个post也蛮有意思的...