I’ve the next code to indicate a rankings immediate when the consumer comes again to the app a second time and hasn’t seen the immediate. It asks the consumer to price my app within the app retailer. I am on the newest model of iOS.
After I name RatingPrompt.trackVisitAndShowPromptIfNeeded()
, despite the fact that the situations are met (the consumer hasn’t seen the immediate and it has been greater than 1 day since they first visited the app), the immediate does not present.
What am I doing improper?
import StoreKit
import UIKit
struct RatingPrompt {
personal static let firstVisitKey = "firstVisitDate"
personal static let hasShownPromptKey = "hasShownRatingPrompt"
personal static let hasShownAfterFirstSummaryKey = "hasShownAfterFirstSummary"
/// Name when consumer opens the app / visits a most important display screen
static func trackVisitAndShowPromptIfNeeded() {
let defaults = UserDefaults.normal
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
}
// Verify if a minimum of 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 consumer reads their first ebook abstract
static func trackFirstSummaryRead() {
let defaults = UserDefaults.normal
// 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 evaluation
personal static func requestReview() {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.home windows.first {
SKStoreReviewController.requestReview(in: window.windowScene!)
}
}
}