本文介绍了是否可以确定是否已提交SKStore Review Controller。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目的是显示SKStore Review Controller(如果适用)或显示我自己的反馈控制器并将用户重定向到App Store。通过这样做,我可以避免多次询问用户反馈。

My intention is to either display the SKStore​Review​Controller (If applicable) or display my own feedback controller and redirect the user to the App Store. By doing this I can avoid asking the user for feedback more than once.

阅读Apple缺少SKStore Review Controller的文档后()似乎无法确定SKStore是否存在审核控制器目前已经提交或之前已经提交过。

After reading Apple's lacking documentation on SKStore​Review​Controller (https://developer.apple.com/reference/storekit/skstorereviewcontroller) it seems that there is no way to determine if SKStore​Review​Controller is currently presented or has been presented previously.

我知道我可能会将显示频率存储在NSUserDefaults中,但我宁愿避免这样做。

I understand that I could potentially store the display frequency in NSUserDefaults, but I would prefer to avoid doing so.

推荐答案

以下是检测是否已呈现的方法。

Here is how I detect if it has been presented.

private static func checkIfShownSKStoreReviewController(_ iteration: Int, originalWindowCount: Int) {
    let windows = UIApplication.shared.windows
    if windows.count > originalWindowCount {
        let window = windows[1]

        if window.className == "UITextEffectsWindow" || window.className == "UIRemoteKeyboardWindow" {
            print("Shown SKVC iteration: \(iteration)")

            //Do logic stuff like saving to your database
            return
        }
    }

    if iteration > 2000 {
        print("checkIfShownSKStoreReviewController: timeout, bailing \(iteration)")
        return
    }

    runThisAfterDelay(seconds: 0.02, after: {
        checkIfShownSKStoreReviewController(iteration + 1, originalWindowCount: originalWindowCount)
    })
}

private static func runThisAfterDelay(seconds seconds: Double, after: () -> ()) {
    let time = dispatch_time(DISPATCH_TIME_NOW, Int64(seconds * Double(NSEC_PER_SEC)))
    dispatch_after(time, dispatch_get_main_queue(), after)
}

static func showReview() {
    print("Showing AppStore Review")
    if #available(iOS 10.3, *) {
        SKStoreReviewController.requestReview()
        checkIfShownSKStoreReviewController(0, originalWindowCount: UIApplication.shared.windows.count)
    }
}

这篇关于是否可以确定是否已提交SKStore Review Controller。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 11:02