如何使用requestReview(SKStore Review Controller)在一段随机时间后在当前viewController中显示查看弹出窗口 [英] How to use requestReview (SKStore​Review​Controller) to show review popup in the current viewController after a random period of time

查看:554
本文介绍了如何使用requestReview(SKStore Review Controller)在一段随机时间后在当前viewController中显示查看弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了iOS 10.3中提供的这一新功能,并认为它更灵活,开箱即用。但在我阅读了 docs 后,我发现你需要决定时间显示它和调用它的viewController。有没有什么方法可以在任何viewController在那一刻显示的随机时间段之后触发它?

I've read about this new feature available in iOS 10.3 and thought it will be more flexible and out of the box. But after I read the docs I found out that you need to decide the time to show it and the viewController who calls it. Is there any way I can make it trigger after a random period of time in any viewController is showing at that moment?

推荐答案

在你的AppDelegate中:

In your 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:

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时会显示评级提示。

The code above will ask Apple to prompt the user to rate the app at a random time between 50 and 500 seconds after the app finishes launching. Remember that according to Apple's docs, there is no guarantee that the rating prompt will be presented when the requestReview is called.

这篇关于如何使用requestReview(SKStore Review Controller)在一段随机时间后在当前viewController中显示查看弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆