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

在阅读了Apple缺乏的关于SKStore Review Controller(https://developer.apple.com/reference/storekit/skstorereviewcontroller)的文档后,似乎无法确定SKStore Review Controller是当前版本还是之前版本。

我知道我可以将显示频率存储在NSUserDefaults中,但我希望避免这样做。

最佳答案

这是我检测是否已提交的方法。

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

关于ios - 是否可以确定是否已提供SKStore Review Controller。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43268014/

10-14 20:16
查看更多