I’ve the next code to point out a rankings immediate when the person comes again to the app a second time and hasn’t seen the immediate. It asks the person to charge my app within the app retailer. I am on the most recent 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 does not present.
What am I doing incorrect?
import StoreKit
import UIKit
struct RatingPrompt {
personal static let firstVisitKey = "firstVisitDate"
personal static let hasShownPromptKey = "hasShownRatingPrompt"
personal static let hasShownAfterFirstSummaryKey = "hasShownAfterFirstSummary"
/// Name when person opens the app / visits a foremost 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 at the very least 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 ebook 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
}
/// Inside helper to request overview
personal static func requestReview() {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.home windows.first {
SKStoreReviewController.requestReview(in: window.windowScene!)
}
}
}