Skip to content

Commit 6a93ec0

Browse files
NMC 1998 - update tracking changes
1 parent 40d99d6 commit 6a93ec0

6 files changed

Lines changed: 118 additions & 125 deletions

File tree

iOSClient/AppDelegate.swift

Lines changed: 44 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Queuer
1313
import EasyTipView
1414
import SwiftUI
1515
import RealmSwift
16+
import MoEngageInApps
1617

1718
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
1819
var backgroundSessionCompletionHandler: (() -> Void)?
@@ -35,6 +36,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
3536

3637
var bgTask: UIBackgroundTaskIdentifier = .invalid
3738
var pushSubscriptionTask: Task<Void, Never>?
39+
40+
let database = NCManageDatabase.shared
41+
3842
var window: UIWindow?
3943
var sceneIdentifier: String = ""
4044
var activeViewController: UIViewController?
@@ -44,7 +48,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
4448
var userId: String = ""
4549
var password: String = ""
4650
var timerErrorNetworking: Timer?
47-
51+
var tipView: EasyTipView?
52+
4853
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
4954
if isUiTestingEnabled {
5055
Task {
@@ -68,11 +73,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
6873

6974
UserDefaults.standard.register(defaults: ["UserAgent": userAgent])
7075

71-
if !NCPreferences().disableCrashservice, !NCBrandOptions.shared.disable_crash_service {
72-
FirebaseApp.configure()
73-
}
76+
// #if !DEBUG
77+
// if !NCPreferences().disableCrashservice, !NCBrandOptions.shared.disable_crash_service {
78+
// FirebaseApp.configure()
79+
// }
80+
// #endif
7481

7582
NCBrandColor.shared.createUserColors()
83+
NCImageCache.shared.createImagesCache()
7684

7785
// Setup Networking
7886
//
@@ -110,6 +118,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
110118
review.showStoreReview()
111119
#endif
112120

121+
// BACKGROUND TASK
122+
//
113123
BGTaskScheduler.shared.register(forTaskWithIdentifier: global.refreshTask, using: backgroundQueue) { task in
114124
guard let appRefreshTask = task as? BGAppRefreshTask else {
115125
task.setTaskCompleted(success: false)
@@ -131,18 +141,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
131141
if NCBrandOptions.shared.enforce_passcode_lock {
132142
NCPreferences().requestPasscodeAtStart = true
133143
}
134-
135-
// if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
136-
// for window in windowScene.windows {
137-
// let imageViews = window.allImageViews()
138-
// // Do something with the imageViews
139-
// for imageView in imageViews {
140-
// print("Found image view: \(imageView)")
141-
// imageView.tintColor = UITraitCollection.current.userInterfaceStyle == .dark ? .white : .black
142-
// }
143-
// }
144-
// }
145144

145+
adjust.configAdjust()
146+
adjust.subsessionStart()
147+
TealiumHelper.shared.start()
148+
FirebaseApp.configure()
149+
150+
// Initialize MoEngage early in app lifecycle
151+
MoEngageAnalytics.setupIfNeeded()
152+
146153
return true
147154
}
148155

@@ -223,12 +230,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
223230
task.setTaskCompleted(success: true)
224231
}
225232

226-
guard let tblAccount = await NCManageDatabase.shared.getActiveTableAccountAsync() else {
227-
nkLog(tag: self.global.logTagTask, emoji: .info, message: "No active account or background task already running")
228-
return
229-
}
230-
231-
await backgroundSync(tblAccount: tblAccount, task: task)
233+
await backgroundSync(task: task)
232234
}
233235
}
234236

@@ -309,12 +311,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
309311
guard !expired else { return }
310312

311313
let err = await NCNetworking.shared.createFolderForAutoUpload(
312-
serverUrlFileName: meta.serverUrlFileName,
313-
account: meta.account
314+
serverUrlFileName: metadata.serverUrlFileName,
315+
account: metadata.account
314316
)
315317
// Fail-fast: abort the whole sync on first failure
316318
if err != .success {
317-
nkLog(tag: self.global.logTagBgSync, emoji: .error, message: "Create folder '\(meta.serverUrlFileName)' failed: \(err.errorCode) – aborting sync")
319+
nkLog(tag: self.global.logTagBgSync, emoji: .error, message: "Create folder '\(metadata.serverUrlFileName)' failed: \(err.errorCode) – aborting sync")
318320
return
319321
}
320322
}
@@ -397,11 +399,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
397399
}
398400

399401
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
400-
guard !isXcodeRunningForPreviews,
401-
application.applicationState != .background else {
402-
return
403-
}
404-
405402
if let deviceToken = NCPushNotificationEncryption.shared().string(withDeviceToken: deviceToken) {
406403
NCPreferences().deviceTokenPushNotification = deviceToken
407404
pushSubscriptionTask = Task.detached {
@@ -412,7 +409,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
412409
return
413410
}
414411

415-
try? await Task.sleep(for: .seconds(1))
412+
try? await Task.sleep(nanoseconds: 1_000_000_000)
416413

417414
let tblAccounts = await NCManageDatabase.shared.getAllTableAccountAsync()
418415
for tblAccount in tblAccounts {
@@ -429,14 +426,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
429426
}
430427

431428
func nextcloudPushNotificationAction(data: [String: AnyObject]) {
429+
guard let data = NCApplicationHandle().nextcloudPushNotificationAction(data: data)
430+
else {
431+
return
432+
}
432433
let account = data["account"] as? String ?? "unavailable"
433434
let app = data["app"] as? String
434435

435436
func openNotification(controller: NCMainTabBarController) {
436437
if app == NCGlobal.shared.termsOfServiceName {
437438
Task {
438439
await NCNetworking.shared.transferDispatcher.notifyAllDelegatesAsync { delegate in
439-
try? await Task.sleep(for: .seconds(0.5))
440+
try? await Task.sleep(nanoseconds: 500_000_000)
440441
delegate.transferReloadDataSource(serverUrl: nil, requestData: true, status: nil)
441442
}
442443
}
@@ -459,18 +460,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
459460
openNotification(controller: controller)
460461
}
461462
} else {
462-
let message = String(
463-
format: NSLocalizedString("account_does_not_exist", comment: ""),
464-
account
465-
)
466-
463+
let message = NSLocalizedString("_the_account_", comment: "") + " " + account + " " + NSLocalizedString("_does_not_exist_", comment: "")
467464
let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
468465
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
469466
UIApplication.shared.mainAppWindow?.rootViewController?.present(alertController, animated: true, completion: { })
470467
}
471468
}
472469

473-
// MARK: - Trust Certificate Error
470+
// MARK: -
474471

475472
func trustCertificateError(host: String) {
476473
guard let activeTblAccount = NCManageDatabase.shared.getActiveTableAccount(),
@@ -499,11 +496,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
499496
let viewController = navigationController.topViewController as? NCViewCertificateDetails {
500497
viewController.delegate = self
501498
viewController.host = host
502-
UIApplication.shared.firstWindow?.rootViewController?.present(navigationController, animated: true)
499+
UIApplication.shared.mainAppWindow?.rootViewController?.present(navigationController, animated: true)
503500
}
504501
}))
505502

506-
UIApplication.shared.firstWindow?.rootViewController?.present(alertController, animated: true)
503+
UIApplication.shared.mainAppWindow?.rootViewController?.present(alertController, animated: true)
507504
}
508505

509506
// MARK: - Reset Application
@@ -680,90 +677,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
680677
guard !account.isEmpty, NCKeychain().getPassword(account: account).isEmpty else { return }
681678
openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
682679
}
683-
684-
// MARK: -
685-
686-
func trustCertificateError(host: String) {
687-
guard let activeTblAccount = NCManageDatabase.shared.getActiveTableAccount(),
688-
let currentHost = URL(string: activeTblAccount.urlBase)?.host,
689-
let pushNotificationServerProxyHost = URL(string: NCBrandOptions.shared.pushNotificationServerProxy)?.host,
690-
host != pushNotificationServerProxyHost,
691-
host == currentHost
692-
else { return }
693-
let certificateHostSavedPath = NCUtilityFileSystem().directoryCertificates + "/" + host + ".der"
694-
var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
695-
696-
if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
697-
title = NSLocalizedString("_connect_server_anyway_", comment: "")
698-
}
699-
700-
let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
701-
702-
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { _ in
703-
NCNetworking.shared.writeCertificate(host: host)
704-
}))
705-
706-
alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { _ in }))
707-
708-
alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { _ in
709-
if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController,
710-
let viewController = navigationController.topViewController as? NCViewCertificateDetails {
711-
viewController.delegate = self
712-
viewController.host = host
713-
UIApplication.shared.mainAppWindow?.rootViewController?.present(navigationController, animated: true)
714-
}
715-
}))
716-
717-
UIApplication.shared.mainAppWindow?.rootViewController?.present(alertController, animated: true)
718-
}
719-
720-
// MARK: - Account
721-
722-
@objc func changeAccount(_ account: String, userProfile: NKUserProfile?) {
723-
// NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeUser)
724-
}
725-
726-
@objc func deleteAccount(_ account: String, wipe: Bool) {
727-
NCAccount().deleteAccount(account, wipe: wipe)
728-
}
729-
730-
func deleteAllAccounts() {
731-
let accounts = NCManageDatabase.shared.getAccounts()
732-
accounts?.forEach({ account in
733-
deleteAccount(account, wipe: true)
734-
})
735-
}
736-
737-
func updateShareAccounts() -> Error? {
738-
return NCAccount().updateAppsShareAccounts()
739-
}
740-
741-
// MARK: - Reset Application
742-
743-
@objc func resetApplication() {
744-
let utilityFileSystem = NCUtilityFileSystem()
745-
746-
NCNetworking.shared.cancelAllTask()
747-
748-
URLCache.shared.removeAllCachedResponses()
749-
750-
utilityFileSystem.removeGroupDirectoryProviderStorage()
751-
utilityFileSystem.removeGroupApplicationSupport()
752-
utilityFileSystem.removeDocumentsDirectory()
753-
utilityFileSystem.removeTemporaryDirectory()
754-
755-
NCPreferences().removeAll()
756-
// NCKeychain().removeAll()
757-
// NCNetworking.shared.removeAllKeyUserDefaultsData(account: nil)
758-
759-
exit(0)
760-
}
761-
762-
// MARK: - Universal Links
763-
764-
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
765-
return false
766-
}
767680
}
768681

769682
// MARK: - Extension
@@ -783,3 +696,11 @@ extension AppDelegate: NCCreateFormUploadConflictDelegate {
783696
}
784697
}
785698
}
699+
700+
//MARK: NMC Customisation
701+
extension AppDelegate {
702+
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
703+
return self.orientationLock
704+
}
705+
}
706+

iOSClient/Helper/AdjustHelper.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,4 @@ -(void)trackEvent:(TriggerEvent)event {
151151
}
152152

153153
@end
154+

iOSClient/Helper/TealiumHelper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ class TealiumHelper: NSObject {
5353
TealiumHelper.shared.tealium?.track(tealEvent)
5454
}
5555
}
56+

iOSClient/Nextcloud-Bridging-Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#import "UIImage+animatedGIF.h"
88
#import "NCPushNotificationEncryption.h"
99
#import "TOPasscodeViewController.h"
10+
#import "TOPasscodeSettingsViewController.h"
1011
#import "AdjustHelper.h"

0 commit comments

Comments
 (0)