Skip to content

Commit 20a50b1

Browse files
NMC 2575 - App update changes
1 parent 92b0a7c commit 20a50b1

2 files changed

Lines changed: 17 additions & 54 deletions

File tree

iOSClient/AppUpdate/AppUpdater.swift

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class AppUpdater {
2929
}
3030
}
3131
}
32-
33-
func showUpdateAlert(version: String, isForceUpdate: Bool){
32+
33+
func showUpdateAlert(version: String, isForceUpdate: Bool) {
3434
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, let viewControlller = appDelegate.window?.rootViewController else { return }
3535
let descriptionMsg = String(format: NSLocalizedString("update_description", comment: ""), version)
3636
let alert = UIAlertController(title: NSLocalizedString("update_available", comment: ""), message: descriptionMsg, preferredStyle: .alert)
@@ -47,7 +47,7 @@ class AppUpdater {
4747
alert.preferredAction = updateAction
4848
viewControlller.present(alert, animated: true, completion: {})
4949
}
50-
50+
5151
func checkLastUpdate() -> Bool {
5252
if let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate) as? Date {
5353
return daysBetweenDate(from: lastUpdateCheckDate) > 7
@@ -56,7 +56,7 @@ class AppUpdater {
5656
}
5757
}
5858

59-
func checkUpdate(completion: @escaping (String?, Bool?) -> Void) {
59+
func checkUpdate(completion: @escaping (String?, Bool?) -> Void) {
6060
let remoteConfig = RemoteConfig.remoteConfig()
6161
remoteConfig.fetch(withExpirationDuration: 1) { (status, error) in
6262
if status == .success {
@@ -70,21 +70,12 @@ class AppUpdater {
7070
// if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
7171
if iOSVersion != currentVersion {
7272
// There is an update available
73-
completion(iOSVersionString,isForcheUpdate)
73+
completion(iOSVersionString, isForcheUpdate)
7474
} else {
7575
completion(nil, nil)
7676
}
7777
}
78-
// let iOSVersion = remoteConfig["ios_app_version"].stringValue ?? "default_value"
79-
// let isForcheUpdate = remoteConfig["ios_force_update"].boolValue
80-
// if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
81-
// if iOSVersion != currentVersion {
82-
// // There is an update available
83-
// completion(iOSVersion,isForcheUpdate)
84-
// } else {
85-
// completion(nil, nil)
86-
// }
87-
// }
78+
8879
}
8980
} else {
9081
// Handle error
@@ -93,11 +84,11 @@ class AppUpdater {
9384
}
9485
}
9586
}
96-
87+
9788
func saveAppUpdateCheckDate() {
9889
UserDefaults.standard.setValue(Date(), forKey: AppUpdaterKey.lastUpdateCheckDate)
9990
}
100-
91+
10192
func daysBetweenDate(from date: Date) -> Int {
10293
return Calendar.current.dateComponents([.day], from: date, to: Date()).day ?? 0
10394
}

iOSClient/SceneDelegate.swift

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
114114
NCPreferences().removeAll()
115115

116116
if let bundleID = Bundle.main.bundleIdentifier {
117-
let lastUpdateCheckDate = UserDefaults.standard.object(forKey: AppUpdaterKey.lastUpdateCheckDate)
118117
UserDefaults.standard.removePersistentDomain(forName: bundleID)
119-
if lastUpdateCheckDate != nil {
120-
UserDefaults.standard.setValue(lastUpdateCheckDate, forKey: AppUpdaterKey.lastUpdateCheckDate)
121-
}
122118
}
123119

124120
if NCBrandOptions.shared.disable_intro {
@@ -128,7 +124,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
128124
window?.makeKeyAndVisible()
129125
}
130126
} else {
131-
if let navigationController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() as? UINavigationController {
127+
if let viewController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() as? NCIntroViewController {
128+
let navigationController = UINavigationController(rootViewController: viewController)
132129
window?.rootViewController = navigationController
133130
window?.makeKeyAndVisible()
134131
}
@@ -211,15 +208,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
211208

212209
func sceneWillEnterForeground(_ scene: UIScene) {
213210
hidePrivacyProtectionWindow()
214-
211+
215212
if let rootHostingController = scene.rootHostingController() {
216213
if rootHostingController.anyRootView is Maintenance {
217214
return
218215
}
219216
}
220217
let session = SceneManager.shared.getSession(scene: scene)
221218
let controller = SceneManager.shared.getController(scene: scene)
222-
219+
223220
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
224221
Task {
225222
if let tableAccount = await self.database.getTableAccountAsync(account: session.account) {
@@ -229,29 +226,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
229226
}
230227
}
231228
AppUpdater().checkForUpdate()
232-
229+
233230
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus)
231+
activateSceneForAccount(scene, account: session.account, controller: controller)
234232
}
235233

236234
func sceneDidBecomeActive(_ scene: UIScene) {
237-
let session = SceneManager.shared.getSession(scene: scene)
238-
let controller = SceneManager.shared.getController(scene: scene)
239-
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Scene did become active")
240-
241-
let oldVersion = UserDefaults.standard.value(forKey: NCSettingsBundleHelper.SettingsBundleKeys.BuildVersionKey) as? String
242-
AppUpdater().checkForUpdate()
243-
AnalyticsHelper.shared.trackAppVersion(oldVersion: oldVersion)
244-
if let userAccount = NCManageDatabase.shared.getActiveTableAccount() {
245-
AnalyticsHelper.shared.trackUsedStorageData(quotaUsed: userAccount.quotaUsed)
246-
}
247-
248-
NCSettingsBundleHelper.setVersionAndBuildNumber()
249-
NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0.5)
250-
251-
// if !NCAskAuthorization().isRequesting {
252-
// NCPasscode.shared.hidePrivacyProtectionWindow()
253-
// }
254-
255235
hidePrivacyProtectionWindow()
256236

257237
if !NextcloudKit.shared.isNetworkReachable(),
@@ -266,13 +246,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
266246
}
267247
}
268248

269-
// func sceneDidBecomeActive(_ scene: UIScene) {
270-
// let session = SceneManager.shared.getSession(scene: scene)
271-
// guard !session.account.isEmpty else { return }
272-
//
273-
// hidePrivacyProtectionWindow()
274-
// }
275-
276249
func sceneWillResignActive(_ scene: UIScene) {
277250
nkLog(debug: "Scene will resign active")
278251

@@ -281,6 +254,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
281254
return
282255
}
283256

257+
WidgetCenter.shared.reloadAllTimelines()
258+
284259
if NCPreferences().privacyScreenEnabled {
285260
showPrivacyProtectionWindow()
286261
}
@@ -290,6 +265,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
290265
let app = UIApplication.shared
291266
var bgID: UIBackgroundTaskIdentifier = .invalid
292267
let isBackgroundRefreshStatus = (UIApplication.shared.backgroundRefreshStatus == .available)
268+
// Must be outside the Task otherwise isSuspendingDatabaseOperation suspends it
293269
let session = SceneManager.shared.getSession(scene: scene)
294270
guard let tblAccount = NCManageDatabase.shared.getTableAccount(predicate: NSPredicate(format: "account == %@", session.account)) else {
295271
return
@@ -542,10 +518,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
542518
}
543519

544520
private func showPrivacyProtectionWindow() {
545-
guard privacyProtectionWindow == nil else {
546-
privacyProtectionWindow?.isHidden = false
547-
return
548-
}
549521
guard let windowScene = self.window?.windowScene else {
550522
return
551523
}

0 commit comments

Comments
 (0)