Tune app review prompt cadence

This commit is contained in:
alexandrev-tibco
2026-02-01 11:35:36 +01:00
parent edfd7a2a56
commit 0ddee49dd5
2 changed files with 46 additions and 0 deletions
@@ -0,0 +1,45 @@
import StoreKit
import UIKit
final class ReviewPromptService {
static let shared = ReviewPromptService()
private let lastPromptKey = "reviewPromptLastDate"
private let checkInCountKey = "reviewPromptCheckinCount"
private let minCheckInsBetweenPrompts = 3
private let minDaysBetweenPrompts = 90
private init() {}
func recordMonthlyCheckInCompleted() {
let currentCount = UserDefaults.standard.integer(forKey: checkInCountKey)
UserDefaults.standard.set(currentCount + 1, forKey: checkInCountKey)
requestReviewIfEligible()
}
private func requestReviewIfEligible() {
let now = Date()
if let lastPrompt = UserDefaults.standard.object(forKey: lastPromptKey) as? Date {
let daysSince = now.timeIntervalSince(lastPrompt) / 86_400
if daysSince < Double(minDaysBetweenPrompts) {
return
}
}
let count = UserDefaults.standard.integer(forKey: checkInCountKey)
guard count >= minCheckInsBetweenPrompts else { return }
requestReview()
}
private func requestReview() {
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
if #available(iOS 18.0, *) {
AppStore.requestReview(in: scene)
} else {
SKStoreReviewController.requestReview(in: scene)
}
UserDefaults.standard.set(Date(), forKey: lastPromptKey)
UserDefaults.standard.set(0, forKey: checkInCountKey)
}
}