ios - SKStoreReviewController 在用户第一次启动应用程序时显示

标签 ios swift skstorereviewcontroller

在我的 iOS 应用程序中,我使用 SKStoreReviewController 请求用户对应用程序进行评分。 Apple 文档说将用于请求“给我们评分”弹出窗口的代码放在我们想要的任何地方,他们将决定何时实际显示。 我在应用程序的第一个 View 中编写了以下代码:

func requestReview() {
    SKStoreReviewController.requestReview()
}

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

最佳答案

SKStoreReviewController.requestReview() 在前几次显示弹出窗口( to be exact ,一年中的前 3 次)。

在应用程序委托(delegate)的 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
}

要显示商店评论 Controller 的 View Controller

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

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

关于ios - SKStoreReviewController 在用户第一次启动应用程序时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49198738/

相关文章:

ios - SKStoreReviewController 如何检测用户已在设置中关闭此应用程序评分 (RTA) 或已达到 3 次限制?

ios - 是否可以确定是否已提交 SKStore Review Controller。

ios - 错误: Invariant violation: tried to get frame for out of range index NaN in react-native-ios and fetch-api

iphone - 如何使用 drawRect 在 UIView 中绘制镜像 UIImage?

swift - Xcode 运行时错误日志 : What does the [#:#] mean in AppName[#:#]?

ios - 如何使用swift在折线图中显示json数据

json - Swift JSON 无法解码。在 String、Int、Bool 之间交替产生不同的错误不匹配类型

objective-c - NSNotificationCenter 触摸通知

ios - UILongPressGestureRecognizer 不起作用

ios - SKStoreReviewController.requestReview() 在 Live App 中不起作用