繁体   English   中英

用户首次启动应用程序时将显示SKStoreReviewController

[英]SKStoreReviewController is being displayed the first time user launches the app

在我的iOS应用中,我使用SKStoreReviewController要求用户对应用进行评分。 Apple文档说,将用于请求“ Rate Us”弹出窗口的代码放在我们想要的任何位置,它们将控制何时实际显示它。 我在应用程序的第一个视图中编写了以下代码:

func requestReview() {
    SKStoreReviewController.requestReview()
}

问题在于,弹出窗口会在我的应用程序用户首次启动该应用程序后立即显示给他们,这毫无意义。 有没有什么方法可以控制弹出窗口的外观,并避免在使用一定数量的应用程序之前显示弹出窗口?

SKStoreReviewController.requestReview() 显示前几次弹出窗口( 准确地说 ,一年中的前3次显示弹出窗口)。

创建一个变量,每次在应用程序委托的didFinishLaunchingWithOptions方法中递增,并将其保存到UserDefaults。 之后,您可以检查用户是否打开应用程序足够次数。

AppDelegate中

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    var appLaunches = UserDefaults.standard.integer(forKey: "appLaunches")
    appLaunches += 1
    UserDefaults.standard.set(appLaunches, forKey: "appLaunches")

    return true
}

您要在其中显示商店评论控制器的视图控制器

let appLaunches = UserDefaults.standard.integer(forKey: "appLaunches")

if appLaunches >= [enough number of app launches] {
    SKStoreReviewController.requestReview()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM