diff --git a/DevCleaner.xcodeproj/project.pbxproj b/DevCleaner.xcodeproj/project.pbxproj index af84fb5..b119046 100644 --- a/DevCleaner.xcodeproj/project.pbxproj +++ b/DevCleaner.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 7110B4992030F17B00EDBFA3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7110B4972030F17B00EDBFA3 /* Main.storyboard */; }; 712F999E20D65229003927BC /* Donations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712F999D20D65229003927BC /* Donations.swift */; }; 712F99A020D6810A003927BC /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712F999F20D6810A003927BC /* MessageView.swift */; }; + 7140B617231A81DC005768A7 /* ReviewRequests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7140B616231A81DC005768A7 /* ReviewRequests.swift */; }; 714AB65F22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 714AB65E22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift */; }; 7155325E2061AFD80025EB75 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7155325D2061AFD80025EB75 /* Logger.swift */; }; 715E8C3D216566FD0059A2E5 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 715E8C3C216566FD0059A2E5 /* Weak.swift */; }; @@ -63,6 +64,7 @@ 7110B49B2030F17B00EDBFA3 /* DevCleaner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DevCleaner.entitlements; sourceTree = ""; }; 712F999D20D65229003927BC /* Donations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Donations.swift; sourceTree = ""; }; 712F999F20D6810A003927BC /* MessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageView.swift; sourceTree = ""; }; + 7140B616231A81DC005768A7 /* ReviewRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewRequests.swift; sourceTree = ""; }; 714AB65E22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLogsFileEntry.swift; sourceTree = ""; }; 7155325D2061AFD80025EB75 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; 715E8C3C216566FD0059A2E5 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = ""; }; @@ -189,6 +191,7 @@ 7162E12C209905BC00081E4E /* Preferences.swift */, 712F999D20D65229003927BC /* Donations.swift */, 718D4ABD23140ABA001E9382 /* Files.swift */, + 7140B616231A81DC005768A7 /* ReviewRequests.swift */, ); path = Managers; sourceTree = ""; @@ -417,6 +420,7 @@ 7155325E2061AFD80025EB75 /* Logger.swift in Sources */, 71FD37D7206AD6BE0042812D /* ArchiveFileEntry.swift in Sources */, 71C8ACE020A62B8000E7A13B /* ScanReminders.swift in Sources */, + 7140B617231A81DC005768A7 /* ReviewRequests.swift in Sources */, 7100BEE222F6E771002E82B2 /* Signposts.swift in Sources */, 716667D0221A26BA004D4FC4 /* FileManager+HomeFolder.swift in Sources */, 718D4ABE23140ABA001E9382 /* Files.swift in Sources */, diff --git a/DevCleaner/Managers/Preferences.swift b/DevCleaner/Managers/Preferences.swift index f2bbbda..39cd859 100644 --- a/DevCleaner/Managers/Preferences.swift +++ b/DevCleaner/Managers/Preferences.swift @@ -33,6 +33,7 @@ public final class Preferences { public static let notificationsPeriod = "DCNotificationsPeriodKey" public static let dryRunEnabled = "DCDryRunEnabledKey" public static let totalBytesCleaned = "DCTotalBytesCleaned" + public static let cleansSinceLastReview = "DCCleansSinceLastReview" public static let customArchivesFolder = "DCCustomArchivesFolderKey" public static let customDerivedDataFolder = "DCCustomDerivedDataFolderKey" public static let appFolder = "DCAppFolder" @@ -157,6 +158,23 @@ public final class Preferences { } } + public var cleansSinceLastReview: Int { + get { + if let value = UserDefaults.standard.object(forKey: Keys.cleansSinceLastReview) as? NSNumber { + return value.intValue + } + + return 0 + } + + set { + let numberValue = NSNumber(value: newValue) + UserDefaults.standard.set(numberValue, forKey: Keys.cleansSinceLastReview) + + self.informAllObserversAboutChange(keyThatChanged: Keys.cleansSinceLastReview) + } + } + public var customArchivesFolder: URL? { get { if let archivesPath = UserDefaults.standard.object(forKey: Keys.customArchivesFolder) as? String { diff --git a/DevCleaner/Managers/ReviewRequests.swift b/DevCleaner/Managers/ReviewRequests.swift new file mode 100644 index 0000000..5aebabc --- /dev/null +++ b/DevCleaner/Managers/ReviewRequests.swift @@ -0,0 +1,35 @@ +// +// ReviewRequests.swift +// DevCleaner +// +// Created by Konrad Kołakowski on 31/08/2019. +// Copyright © 2019 One Minute Games. All rights reserved. +// + +import Foundation +import StoreKit + +public final class ReviewRequests { + // MARK: Properties + public static let shared = ReviewRequests() + + // MARK: Constants + private static let bytesNeededForReviewRequest: Int64 = 20 * 1024 * 1024 * 1024 // 20GB + private static let cleansNeededForReviewRequest = 3 + + // MARK: Showing review request + public func requestReviewIfNeeded() { + let totalBytesCleaned = Preferences.shared.totalBytesCleaned + let totalCleansPerformedSinceLastRequest = Preferences.shared.cleansSinceLastReview + + // desired rules: + // we show it either if we passed TOTAL of 20GB of cleaned bytes, which may be even on the first run of the app + // or, if we clean smaller amounts, after 3 cleans + // after we pass those 20GB total cleaned amount, we ask everytime we clean basically + if totalBytesCleaned > ReviewRequests.bytesNeededForReviewRequest || totalCleansPerformedSinceLastRequest >= ReviewRequests.cleansNeededForReviewRequest { + SKStoreReviewController.requestReview() + + Preferences.shared.cleansSinceLastReview = 0 + } + } +}