Skip to content

Commit

Permalink
Add First Launch Logic (#28)
Browse files Browse the repository at this point in the history
- Add first launch logic in AppReviewManager so it does not prompt user on first time launch

Co-authored-by: James Layton <>
  • Loading branch information
RedDragonJ authored Aug 6, 2024
1 parent 66210ac commit 550a0cf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/JimUtilitySDK/AppReviewManager/AppReviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ import UIKit
public class AppReviewManager {
private static let lastReviewPromptDateKey = "LastReviewPromptDate"
private static let hasReviewedKey = "HasReviewed"
private static let hasLaunchedKey = "HasLaunched"
private static let reviewPromptInterval: TimeInterval = 72 * 60 * 60 // 72 hours in seconds

// FOR UIKit
/// Checks if the app review request should be presented to the user based on the review status and time interval.
public static func checkAppReview() {
let userDefaults = UserDefaults.standard

// Check if this is the first launch
if !userDefaults.bool(forKey: hasLaunchedKey) {
userDefaults.set(true, forKey: hasLaunchedKey)
return
}

let hasReviewed = userDefaults.bool(forKey: hasReviewedKey)
let lastPromptDate = (userDefaults.object(forKey: lastReviewPromptDateKey) as? Date) ?? Date.distantPast
let currentDate = Date()
Expand Down Expand Up @@ -45,6 +53,14 @@ public class AppReviewManager {
/// Checks if the app review request should be presented to the user based on the review status and time interval.
public static func checkAppReview(completion: @escaping (Bool) -> Void) {
let userDefaults = UserDefaults.standard

// Check if this is the first launch
if !userDefaults.bool(forKey: hasLaunchedKey) {
userDefaults.set(true, forKey: hasLaunchedKey)
completion(false)
return
}

let hasReviewed = userDefaults.bool(forKey: hasReviewedKey)
let lastPromptDate = (userDefaults.object(forKey: lastReviewPromptDateKey) as? Date) ?? Date.distantPast
let currentDate = Date()
Expand Down

0 comments on commit 550a0cf

Please sign in to comment.