Skip to content

Commit

Permalink
Add skip backup setting to iCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jCalaU committed Jul 31, 2020
1 parent 71376f0 commit 0c92bd1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Prey/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
GAI.sharedInstance().logger.logLevel = GAILogLevel.none
GAI.sharedInstance().defaultTracker.allowIDFACollection = true

// Check settings info
checkSettingsToBackup()

// Update current localUserSettings with preview versions
PreyConfig.sharedInstance.updateUserSettings()

Expand Down Expand Up @@ -272,4 +275,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

// MARK: Check settings on backup

// check settings
func checkSettingsToBackup() {
let fileManager = FileManager.default
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
let docURL = urls[urls.endIndex-1]
let storeURL = docURL.appendingPathComponent("skpBckp")

if !fileManager.fileExists(atPath: storeURL.path) {
// Not exist skipBackup file
// Check if app was restored from iCloud
if PreyConfig.sharedInstance.isRegistered && PreyConfig.sharedInstance.existBackup {
PreyConfig.sharedInstance.resetValues()
}
fileManager.createFile(atPath: storeURL.path, contents: nil, attributes: nil)
_ = self.addSkipBackupAttributeToItemAtURL(filePath: storeURL.path)
PreyConfig.sharedInstance.existBackup = true
PreyConfig.sharedInstance.saveValues()
}
}

// Add skip backup
func addSkipBackupAttributeToItemAtURL(filePath:String) -> Bool {
let URL:NSURL = NSURL.fileURL(withPath: filePath) as NSURL
assert(FileManager.default.fileExists(atPath: filePath), "File \(filePath) does not exist")
var success: Bool
do {
try URL.setResourceValue(true, forKey:URLResourceKey.isExcludedFromBackupKey)
success = true
} catch let error as NSError {
success = false
PreyLogger("Error: \(error) excluding from backup");
}
return success
}
}
4 changes: 4 additions & 0 deletions Prey/Classes/PreyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum PreyConfigDevice: String {
case NeedChangeIcon
case IsTouchIDEnabled
case ValidationUserEmail
case ExistBackup
}

enum PreyUserEmailValidation: String {
Expand Down Expand Up @@ -70,6 +71,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
isTouchIDEnabled = defaultConfig.bool(forKey: PreyConfigDevice.IsTouchIDEnabled.rawValue)
reportOptions = defaultConfig.object(forKey: PreyConfigDevice.ReportOptions.rawValue) as? NSDictionary
validationUserEmail = defaultConfig.string(forKey: PreyConfigDevice.ValidationUserEmail.rawValue)
existBackup = defaultConfig.bool(forKey: PreyConfigDevice.ExistBackup.rawValue)
}

// MARK: Properties
Expand All @@ -90,6 +92,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
var isTouchIDEnabled : Bool
var reportOptions : NSDictionary?
var validationUserEmail : String?
var existBackup : Bool

// MARK: Functions

Expand All @@ -113,6 +116,7 @@ class PreyConfig: NSObject, UIActionSheetDelegate {
defaultConfig.set(isTouchIDEnabled, forKey:PreyConfigDevice.IsTouchIDEnabled.rawValue)
defaultConfig.set(reportOptions, forKey:PreyConfigDevice.ReportOptions.rawValue)
defaultConfig.set(validationUserEmail, forKey:PreyConfigDevice.ValidationUserEmail.rawValue)
defaultConfig.set(existBackup, forKey: PreyConfigDevice.ExistBackup.rawValue)
}

// Reset values on NSUserDefaults
Expand Down

0 comments on commit 0c92bd1

Please sign in to comment.