2017-04-07 61 views
5

我的意圖是顯示SKStore Review Controller(如果適用)或顯示我自己的反饋控制器並將用戶重定向到App Store。通過這樣做,我可以避免不止一次詢問用戶的反饋意見。是否可以確定SKStore Review Controller是否已經出現。

在閱讀Apple缺乏關於SKStore Review Controller(https://developer.apple.com/reference/storekit/skstorereviewcontroller)的文檔後,似乎無法確定SKStore Review Controller目前是否已呈現或已經呈現過。

我知道我可以將顯示頻率存儲在NSUserDefaults中,但我寧願避免這樣做。

+0

你說你不想使用UserDefaults但即使有一個方法來確定是否SKStore查看控制器目前提出或已經提出以前那麼你將如何保存的價值呢? 但我會檢查[this](http://stackoverflow.com/questions/43075515/how-to-use-requestreview-skstorereviewcontroller-to-show-review-popup-in-the)的答案。 –

+0

[SKStoreReviewController如何檢測到用戶已關閉此應用程序(RTA)設置或3次限制的可能重複已達到?](https://stackoverflow.com/questions/42533520/skstorereviewcontroller-how-to-detect -hat-user-has-turn-off-rate-this-app-rt) –

回答

-3

其實這取決於你有層次結構。如果您正在使用一個導航控制器

for (vc in self.navigationController.viewControllers) { 
if (vc isKindOfClass(SKStore​Review​Controller)){ 

//Means it is present 
    } 
} 
+1

這不起作用。我不相信SKStoreReviewController將任何東西添加到導航堆棧。 – Lachlan

0

以下是我如何檢測它是否已被呈現。

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

感謝您的回答。儘管它在理論上可行,但這並不是我正在尋找的。 潛在的等待40秒並不理想,然後用另一個反饋/審查控制器更新UI。 雖然說這是迄今爲止我見過的最好的迴應,它應該最終確定是否已經顯示視圖(假設它將在40秒內呈現) – Lachlan

+1

嗯,在我的嘗試中,它通常在2-第10次迭代。所以最多0.2秒。但我相信它會因不同的因素而有所不同。如果你喜歡,你可以使用迭代計數並在5秒後發送消息。 – Esqarrouth

相關問題