Is it possible determine if SKStore​Review​Controller has been presented.

你。 提交于 2019-11-27 18:35:31

问题


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.

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.

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


回答1:


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)
    }
}


来源:https://stackoverflow.com/questions/43268014/is-it-possible-determine-if-skstorereviewcontroller-has-been-presented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!