Skip to content

Commit

Permalink
Fixed issues with user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
leathalman committed May 26, 2022
1 parent 86cbce0 commit d408575
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions Jotify/Controller/Settings/AccountSettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class AccountSettingsController: SettingsController {
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
User.updateSettings()
}
} else {
let alertController = UIAlertController(title: "Error", message: "There was an error resetting settings. Please try again later.", preferredStyle: .alert)
Expand Down
28 changes: 28 additions & 0 deletions Jotify/Controller/SetupController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,43 @@ class SetupController {
SetupController.firstLauch = true
setupWidget()
setupDefaults()
checkForRestorePurchase()
} else {
// first launch
print("first launch")
SetupController.firstLauch = true
setupWidget()
setupDefaults()
checkForRestorePurchase()
}
defaults.set(currentVersion, forKey: shortVersionKey)
}
}

func checkForRestorePurchase() {
IAPManager.shared.restorePurchases { (result) in
DispatchQueue.main.async {
switch result {
case .success(let success):
if success {
//unlock premium
DataManager.updateUserSettings(setting: "hasPremium", value: true) { success in
if !success! {
print("Error granting premium from restore")
}
print("User settings updated...")
User.settings?.hasPremium = true
}
} else {
//no products were found
print("Nothing to automatically restore...")
}

case .failure(let error):
//there was an error
print("\(error) restoring IAP")
}
}
}
}
}
1 change: 1 addition & 0 deletions Jotify/Model/Firebase/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DataManager {
"defaultView": 0,
"referrals": 0,
"referralLink": "",
"hasPremium": false
]) { (error) in
if let error = error {
print("Error deleting document: \(error.localizedDescription)")
Expand Down

0 comments on commit d408575

Please sign in to comment.