I’ve the next code to point out a scores immediate when the person comes again to the app a second time and hasn’t seen the immediate. It asks the person to fee my app within the app retailer. I am on the newest model of iOS.
After I name RatingPrompt.trackVisitAndShowPromptIfNeeded()
, although the circumstances are met (the person hasn’t seen the immediate and it has been greater than 1 day since they first visited the app), the immediate would not present.
What am I doing mistaken?
import StoreKit
import UIKit
struct RatingPrompt {
non-public static let firstVisitKey = "firstVisitDate"
non-public static let hasShownPromptKey = "hasShownRatingPrompt"
non-public static let hasShownAfterFirstSummaryKey = "hasShownAfterFirstSummary"
/// Name when person opens the app / visits a fundamental display screen
static func trackVisitAndShowPromptIfNeeded() {
let defaults = UserDefaults.commonplace
let now = Date()
// Save first go to date
if defaults.object(forKey: firstVisitKey) == nil {
defaults.set(now, forKey: firstVisitKey)
return
}
// If already proven through go to or abstract, do nothing
if defaults.bool(forKey: hasShownPromptKey) {
return
}
// Examine if no less than 1 day handed
if let firstVisit = defaults.object(forKey: firstVisitKey) as? Date {
let oneDay: TimeInterval = 60 * 60 * 24
if now.timeIntervalSince(firstVisit) >= oneDay {
requestReview()
defaults.set(true, forKey: hasShownPromptKey)
}
}
}
/// Name when person reads their first e-book abstract
static func trackFirstSummaryRead() {
let defaults = UserDefaults.commonplace
// If already proven, do nothing
if defaults.bool(forKey: hasShownPromptKey) || defaults.bool(forKey: hasShownAfterFirstSummaryKey) {
return
}
// Present instantly on first abstract learn
requestReview()
defaults.set(true, forKey: hasShownAfterFirstSummaryKey)
defaults.set(true, forKey: hasShownPromptKey) // guarantee it will not present once more
}
/// Inner helper to request overview
non-public static func requestReview() {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.home windows.first {
SKStoreReviewController.requestReview(in: window.windowScene!)
}
}
}