AppDelegate.swift 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. //
  2. // AppDelegate.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14 (19/02/21 swift).
  6. // Copyright (c) 2014 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import BackgroundTasks
  25. import NextcloudKit
  26. import TOPasscodeViewController
  27. import LocalAuthentication
  28. import Firebase
  29. import WidgetKit
  30. @UIApplicationMain
  31. class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, TOPasscodeViewControllerDelegate, NCAccountRequestDelegate, NCViewCertificateDetailsDelegate, NCUserBaseUrl {
  32. var backgroundSessionCompletionHandler: (() -> Void)?
  33. var window: UIWindow?
  34. @objc var account: String = ""
  35. @objc var urlBase: String = ""
  36. @objc var user: String = ""
  37. @objc var userId: String = ""
  38. @objc var password: String = ""
  39. var activeLogin: NCLogin?
  40. var activeLoginWeb: NCLoginWeb?
  41. var activeServerUrl: String = ""
  42. @objc var activeViewController: UIViewController?
  43. var mainTabBar: NCMainTabBar?
  44. var activeMetadata: tableMetadata?
  45. let listFilesVC = ThreadSafeDictionary<String, NCFiles>()
  46. let listFavoriteVC = ThreadSafeDictionary<String, NCFavorite>()
  47. let listOfflineVC = ThreadSafeDictionary<String, NCOffline>()
  48. let listGroupfoldersVC = ThreadSafeDictionary<String, NCGroupfolders>()
  49. var disableSharesView: Bool = false
  50. var documentPickerViewController: NCDocumentPickerViewController?
  51. var timerErrorNetworking: Timer?
  52. private var privacyProtectionWindow: UIWindow?
  53. var isUiTestingEnabled: Bool {
  54. get {
  55. return ProcessInfo.processInfo.arguments.contains("UI_TESTING")
  56. }
  57. }
  58. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  59. if isUiTestingEnabled {
  60. deleteAllAccounts()
  61. }
  62. NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0)
  63. let userAgent = CCUtility.getUserAgent() as String
  64. let versionNextcloudiOS = String(format: NCBrandOptions.shared.textCopyrightNextcloudiOS, NCUtility.shared.getVersionApp())
  65. // Register initialize
  66. NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
  67. UserDefaults.standard.register(defaults: ["UserAgent": userAgent])
  68. if !CCUtility.getDisableCrashservice() && !NCBrandOptions.shared.disable_crash_service {
  69. FirebaseApp.configure()
  70. }
  71. CCUtility.createDirectoryStandard()
  72. CCUtility.emptyTemporaryDirectory()
  73. NextcloudKit.shared.setup(delegate: NCNetworking.shared)
  74. NextcloudKit.shared.setup(userAgent: userAgent)
  75. startTimerErrorNetworking()
  76. // LOG
  77. var levelLog = 0
  78. if let pathDirectoryGroup = CCUtility.getDirectoryGroup()?.path {
  79. NextcloudKit.shared.nkCommonInstance.pathLog = pathDirectoryGroup
  80. }
  81. if NCBrandOptions.shared.disable_log {
  82. NCUtilityFileSystem.shared.deleteFile(filePath: NextcloudKit.shared.nkCommonInstance.filenamePathLog)
  83. NCUtilityFileSystem.shared.deleteFile(filePath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + "/" + NextcloudKit.shared.nkCommonInstance.filenameLog)
  84. } else {
  85. levelLog = CCUtility.getLogLevel()
  86. NextcloudKit.shared.nkCommonInstance.levelLog = levelLog
  87. NextcloudKit.shared.nkCommonInstance.copyLogToDocumentDirectory = true
  88. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start session with level \(levelLog) " + versionNextcloudiOS + " in state \(UIApplication.shared.applicationState.rawValue) where (0 active, 1 inactive, 2 background).")
  89. }
  90. // LOG Account
  91. if let account = NCManageDatabase.shared.getActiveAccount() {
  92. NextcloudKit.shared.nkCommonInstance.writeLog("Account active \(account.account)")
  93. if CCUtility.getPassword(account.account).isEmpty {
  94. NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] PASSWORD NOT FOUND for \(account.account)")
  95. }
  96. }
  97. // Activate user account
  98. if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
  99. settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), initialize: false)
  100. NCBrandColor.shared.settingThemingColor(account: activeAccount.account)
  101. initialize()
  102. } else {
  103. CCUtility.deleteAllChainStore()
  104. if let bundleID = Bundle.main.bundleIdentifier {
  105. UserDefaults.standard.removePersistentDomain(forName: bundleID)
  106. }
  107. NCBrandColor.shared.createImagesThemingColor()
  108. }
  109. // Create user color
  110. NCBrandColor.shared.createUserColors()
  111. // Push Notification & display notification
  112. application.registerForRemoteNotifications()
  113. UNUserNotificationCenter.current().delegate = self
  114. UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
  115. // Store review
  116. if !NCUtility.shared.isSimulatorOrTestFlight() {
  117. let review = NCStoreReview()
  118. review.incrementAppRuns()
  119. review.showStoreReview()
  120. }
  121. // Background task: register
  122. BGTaskScheduler.shared.register(forTaskWithIdentifier: NCGlobal.shared.refreshTask, using: nil) { task in
  123. self.handleRefreshTask(task)
  124. }
  125. BGTaskScheduler.shared.register(forTaskWithIdentifier: NCGlobal.shared.processingTask, using: nil) { task in
  126. self.handleProcessingTask(task)
  127. }
  128. // Intro
  129. if NCBrandOptions.shared.disable_intro {
  130. CCUtility.setIntro(true)
  131. if account.isEmpty {
  132. openLogin(viewController: nil, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
  133. }
  134. } else {
  135. if !CCUtility.getIntro() {
  136. if let viewController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() {
  137. let navigationController = NCLoginNavigationController(rootViewController: viewController)
  138. window?.rootViewController = navigationController
  139. window?.makeKeyAndVisible()
  140. }
  141. }
  142. }
  143. // Passcode
  144. self.presentPasscode {
  145. self.enableTouchFaceID()
  146. }
  147. return true
  148. }
  149. // MARK: - Life Cycle
  150. // L' applicazione entrerà in attivo (sempre)
  151. func applicationDidBecomeActive(_ application: UIApplication) {
  152. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Application did become active")
  153. NCSettingsBundleHelper.setVersionAndBuildNumber()
  154. NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0.5)
  155. // START OBSERVE/TIMER UPLOAD PROCESS
  156. NCNetworkingProcessUpload.shared.observeTableMetadata()
  157. NCNetworkingProcessUpload.shared.startTimer()
  158. if !NCAskAuthorization.shared.isRequesting {
  159. hidePrivacyProtectionWindow()
  160. }
  161. if !account.isEmpty {
  162. NCNetworkingProcessUpload.shared.verifyUploadZombie()
  163. }
  164. // Start Auto Upload
  165. NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
  166. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
  167. }
  168. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationDidBecomeActive)
  169. }
  170. // L' applicazione entrerà in primo piano (dopo il background)
  171. func applicationWillEnterForeground(_ application: UIApplication) {
  172. guard !account.isEmpty, let activeAccount = NCManageDatabase.shared.getActiveAccount() else { return }
  173. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Application will enter in foreground")
  174. if activeAccount.account != account {
  175. settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account))
  176. } else {
  177. // Request Service Server Nextcloud
  178. NCService.shared.startRequestServicesServer()
  179. }
  180. // Required unsubscribing / subscribing
  181. NCPushNotification.shared().pushNotification()
  182. // Request TouchID, FaceID
  183. enableTouchFaceID()
  184. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus)
  185. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSourceNetwork, second: 2)
  186. }
  187. // L' applicazione si dimetterà dallo stato di attivo
  188. func applicationWillResignActive(_ application: UIApplication) {
  189. // Nextcloud update share accounts
  190. if let error = updateShareAccounts() {
  191. NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Create share accounts \(error.localizedDescription)")
  192. }
  193. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Application will resign active")
  194. guard !account.isEmpty else { return }
  195. // STOP OBSERVE/TIMER UPLOAD PROCESS
  196. NCNetworkingProcessUpload.shared.invalidateObserveTableMetadata()
  197. NCNetworkingProcessUpload.shared.stopTimer()
  198. if CCUtility.getPrivacyScreenEnabled() {
  199. // Privacy
  200. showPrivacyProtectionWindow()
  201. }
  202. // Reload Widget
  203. WidgetCenter.shared.reloadAllTimelines()
  204. // Clear operation queue
  205. NCOperationQueue.shared.cancelAllQueue()
  206. // Clear download
  207. NCNetworking.shared.cancelAllDownloadTransfer()
  208. // Clear older files
  209. let days = CCUtility.getCleanUpDay()
  210. if let directory = CCUtility.getDirectoryProviderStorage() {
  211. NCUtilityFileSystem.shared.cleanUp(directory: directory, days: TimeInterval(days))
  212. }
  213. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationWillResignActive)
  214. }
  215. // L' applicazione è entrata nello sfondo
  216. func applicationDidEnterBackground(_ application: UIApplication) {
  217. guard !account.isEmpty else { return }
  218. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Application did enter in background")
  219. scheduleAppRefresh()
  220. scheduleAppProcessing()
  221. // Passcode
  222. presentPasscode { }
  223. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationDidEnterBackground)
  224. }
  225. // L'applicazione terminerà
  226. func applicationWillTerminate(_ application: UIApplication) {
  227. NCNetworking.shared.cancelAllDownloadTransfer()
  228. if UIApplication.shared.backgroundRefreshStatus == .available {
  229. let content = UNMutableNotificationContent()
  230. content.title = NCBrandOptions.shared.brand
  231. content.body = NSLocalizedString("_keep_running_", comment: "")
  232. let req = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
  233. let notificationCenter = UNUserNotificationCenter.current()
  234. notificationCenter.add(req)
  235. }
  236. NextcloudKit.shared.nkCommonInstance.writeLog("bye bye")
  237. }
  238. // MARK: -
  239. @objc private func initialize() {
  240. guard !account.isEmpty else { return }
  241. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] initialize Main")
  242. // Registeration push notification
  243. NCPushNotification.shared().pushNotification()
  244. // Unlock E2EE
  245. NCNetworkingE2EE().unlockAll(account: account)
  246. // Start services
  247. NCService.shared.startRequestServicesServer()
  248. // close detail
  249. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuDetailClose)
  250. // Reload Widget
  251. WidgetCenter.shared.reloadAllTimelines()
  252. // Registeration domain File Provider
  253. // FileProviderDomain *fileProviderDomain = [FileProviderDomain new];
  254. // [fileProviderDomain removeAllDomains];
  255. // [fileProviderDomain registerDomains];
  256. }
  257. // MARK: - Background Task
  258. /*
  259. @discussion Schedule a refresh task request to ask that the system launch your app briefly so that you can download data and keep your app's contents up-to-date. The system will fulfill this request intelligently based on system conditions and app usage.
  260. < MAX 30 seconds >
  261. */
  262. func scheduleAppRefresh() {
  263. let request = BGAppRefreshTaskRequest(identifier: NCGlobal.shared.refreshTask)
  264. request.earliestBeginDate = Date(timeIntervalSinceNow: 60) // Refresh after 60 seconds.
  265. do {
  266. try BGTaskScheduler.shared.submit(request)
  267. NextcloudKit.shared.nkCommonInstance.writeLog("[SUCCESS] Refresh task success submit request 60 seconds \(request)")
  268. } catch {
  269. NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Refresh task failed to submit request: \(error)")
  270. }
  271. }
  272. /*
  273. @discussion Schedule a processing task request to ask that the system launch your app when conditions are favorable for battery life to handle deferrable, longer-running processing, such as syncing, database maintenance, or similar tasks. The system will attempt to fulfill this request to the best of its ability within the next two days as long as the user has used your app within the past week.
  274. < MAX over 1 minute >
  275. */
  276. func scheduleAppProcessing() {
  277. let request = BGProcessingTaskRequest(identifier: NCGlobal.shared.processingTask)
  278. request.earliestBeginDate = Date(timeIntervalSinceNow: 5 * 60) // Refresh after 5 minutes.
  279. request.requiresNetworkConnectivity = false
  280. request.requiresExternalPower = false
  281. do {
  282. try BGTaskScheduler.shared.submit(request)
  283. NextcloudKit.shared.nkCommonInstance.writeLog("[SUCCESS] Background Processing task success submit request 5 minutes \(request)")
  284. } catch {
  285. NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Background Processing task failed to submit request: \(error)")
  286. }
  287. }
  288. func handleRefreshTask(_ task: BGTask) {
  289. scheduleAppRefresh()
  290. guard !account.isEmpty else {
  291. task.setTaskCompleted(success: true)
  292. return
  293. }
  294. NextcloudKit.shared.setup(delegate: NCNetworking.shared)
  295. NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
  296. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task auto upload with \(items) uploads")
  297. NCNetworkingProcessUpload.shared.start { items in
  298. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task upload process with \(items) uploads")
  299. task.setTaskCompleted(success: true)
  300. }
  301. }
  302. }
  303. func handleProcessingTask(_ task: BGTask) {
  304. scheduleAppProcessing()
  305. guard !account.isEmpty else {
  306. task.setTaskCompleted(success: true)
  307. return
  308. }
  309. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task")
  310. task.setTaskCompleted(success: true)
  311. }
  312. // MARK: - Background Networking Session
  313. func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
  314. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start handle Events For Background URLSession: \(identifier)")
  315. // Reload Widget
  316. WidgetCenter.shared.reloadAllTimelines()
  317. backgroundSessionCompletionHandler = completionHandler
  318. }
  319. // MARK: - Push Notifications
  320. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  321. completionHandler([.list, .banner, .sound])
  322. }
  323. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  324. if let pref = UserDefaults(suiteName: NCBrandOptions.shared.capabilitiesGroups),
  325. let data = pref.object(forKey: "NOTIFICATION_DATA") as? [String: AnyObject] {
  326. nextcloudPushNotificationAction(data: data)
  327. pref.set(nil, forKey: "NOTIFICATION_DATA")
  328. }
  329. completionHandler()
  330. }
  331. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  332. NCNetworking.shared.checkPushNotificationServerProxyCertificateUntrusted(viewController: self.window?.rootViewController) { error in
  333. if error == .success {
  334. NCPushNotification.shared().registerForRemoteNotifications(withDeviceToken: deviceToken)
  335. }
  336. }
  337. }
  338. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  339. NCPushNotification.shared().applicationdidReceiveRemoteNotification(userInfo) { result in
  340. completionHandler(result)
  341. }
  342. }
  343. func nextcloudPushNotificationAction(data: [String: AnyObject]) {
  344. guard let data = NCApplicationHandle().nextcloudPushNotificationAction(data: data) else { return }
  345. var findAccount: Bool = false
  346. if let accountPush = data["account"] as? String {
  347. if accountPush == self.account {
  348. findAccount = true
  349. } else {
  350. let accounts = NCManageDatabase.shared.getAllAccount()
  351. for account in accounts {
  352. if account.account == accountPush {
  353. self.changeAccount(account.account)
  354. findAccount = true
  355. }
  356. }
  357. }
  358. if findAccount, let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification {
  359. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  360. let navigationController = UINavigationController(rootViewController: viewController)
  361. navigationController.modalPresentationStyle = .fullScreen
  362. self.window?.rootViewController?.present(navigationController, animated: true)
  363. }
  364. } else if !findAccount {
  365. let message = NSLocalizedString("_the_account_", comment: "") + " " + accountPush + " " + NSLocalizedString("_does_not_exist_", comment: "")
  366. let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
  367. alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
  368. self.window?.rootViewController?.present(alertController, animated: true, completion: { })
  369. }
  370. }
  371. }
  372. // MARK: - Login & checkErrorNetworking
  373. @objc func openLogin(viewController: UIViewController?, selector: Int, openLoginWeb: Bool) {
  374. // [WEBPersonalized] [AppConfig]
  375. if NCBrandOptions.shared.use_login_web_personalized || NCBrandOptions.shared.use_AppConfig {
  376. if activeLoginWeb?.view.window == nil {
  377. activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
  378. activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
  379. showLoginViewController(activeLoginWeb, contextViewController: viewController)
  380. }
  381. return
  382. }
  383. // Nextcloud standard login
  384. if selector == NCGlobal.shared.introSignup {
  385. if activeLoginWeb?.view.window == nil {
  386. activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
  387. if selector == NCGlobal.shared.introSignup {
  388. activeLoginWeb?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
  389. } else {
  390. activeLoginWeb?.urlBase = self.urlBase
  391. }
  392. showLoginViewController(activeLoginWeb, contextViewController: viewController)
  393. }
  394. } else if NCBrandOptions.shared.disable_intro && NCBrandOptions.shared.disable_request_login_url {
  395. if activeLoginWeb?.view.window == nil {
  396. activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
  397. activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
  398. showLoginViewController(activeLoginWeb, contextViewController: viewController)
  399. }
  400. } else if openLoginWeb {
  401. // Used also for reinsert the account (change passwd)
  402. if activeLoginWeb?.view.window == nil {
  403. activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
  404. activeLoginWeb?.urlBase = urlBase
  405. activeLoginWeb?.user = user
  406. showLoginViewController(activeLoginWeb, contextViewController: viewController)
  407. }
  408. } else {
  409. if activeLogin?.view.window == nil {
  410. activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
  411. showLoginViewController(activeLogin, contextViewController: viewController)
  412. }
  413. }
  414. }
  415. func showLoginViewController(_ viewController: UIViewController?, contextViewController: UIViewController?) {
  416. if contextViewController == nil {
  417. if let viewController = viewController {
  418. let navigationController = NCLoginNavigationController(rootViewController: viewController)
  419. navigationController.navigationBar.barStyle = .black
  420. navigationController.navigationBar.tintColor = NCBrandColor.shared.customerText
  421. navigationController.navigationBar.barTintColor = NCBrandColor.shared.customer
  422. navigationController.navigationBar.isTranslucent = false
  423. window?.rootViewController = navigationController
  424. window?.makeKeyAndVisible()
  425. }
  426. } else if contextViewController is UINavigationController {
  427. if let contextViewController = contextViewController, let viewController = viewController {
  428. (contextViewController as! UINavigationController).pushViewController(viewController, animated: true)
  429. }
  430. } else {
  431. if let viewController = viewController, let contextViewController = contextViewController {
  432. let navigationController = NCLoginNavigationController(rootViewController: viewController)
  433. navigationController.modalPresentationStyle = .fullScreen
  434. navigationController.navigationBar.barStyle = .black
  435. navigationController.navigationBar.tintColor = NCBrandColor.shared.customerText
  436. navigationController.navigationBar.barTintColor = NCBrandColor.shared.customer
  437. navigationController.navigationBar.isTranslucent = false
  438. contextViewController.present(navigationController, animated: true) { }
  439. }
  440. }
  441. }
  442. @objc func startTimerErrorNetworking() {
  443. timerErrorNetworking = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(checkErrorNetworking), userInfo: nil, repeats: true)
  444. }
  445. @objc private func checkErrorNetworking() {
  446. if account != "" && CCUtility.getPassword(account)!.count == 0 {
  447. openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
  448. }
  449. }
  450. func trustCertificateError(host: String) {
  451. guard let currentHost = URL(string: self.urlBase)?.host,
  452. let pushNotificationServerProxyHost = URL(string: NCBrandOptions.shared.pushNotificationServerProxy)?.host,
  453. host != pushNotificationServerProxyHost,
  454. host == currentHost
  455. else { return }
  456. let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
  457. var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
  458. if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
  459. title = NSLocalizedString("_connect_server_anyway_", comment: "")
  460. }
  461. let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
  462. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { _ in
  463. NCNetworking.shared.writeCertificate(host: host)
  464. }))
  465. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { _ in }))
  466. alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { _ in
  467. if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
  468. let viewController = navigationController.topViewController as! NCViewCertificateDetails
  469. viewController.delegate = self
  470. viewController.host = host
  471. self.window?.rootViewController?.present(navigationController, animated: true)
  472. }
  473. }))
  474. window?.rootViewController?.present(alertController, animated: true)
  475. }
  476. func viewCertificateDetailsDismiss(host: String) {
  477. trustCertificateError(host: host)
  478. }
  479. // MARK: - Account
  480. @objc func settingAccount(_ account: String, urlBase: String, user: String, userId: String, password: String, initialize: Bool = true) {
  481. let currentAccount = self.account + "/" + self.userId
  482. let newAccount = account + "/" + userId
  483. self.account = account
  484. self.urlBase = urlBase
  485. self.user = user
  486. self.userId = userId
  487. self.password = password
  488. _ = NCActionCenter.shared
  489. NextcloudKit.shared.setup(account: account, user: user, userId: userId, password: password, urlBase: urlBase)
  490. NCManageDatabase.shared.setCapabilities(account: account)
  491. if NCGlobal.shared.capabilityServerVersionMajor > 0 {
  492. NextcloudKit.shared.setup(nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor)
  493. }
  494. DispatchQueue.main.async {
  495. if initialize, UIApplication.shared.applicationState != .background && currentAccount != newAccount && newAccount != "/" {
  496. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize, second: 0.2)
  497. }
  498. }
  499. }
  500. @objc func deleteAccount(_ account: String, wipe: Bool) {
  501. if let account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) {
  502. NCPushNotification.shared().unsubscribingNextcloudServerPushNotification(account.account, urlBase: account.urlBase, user: account.user, withSubscribing: false)
  503. }
  504. let results = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@", account), sorted: "ocId", ascending: false)
  505. for result in results {
  506. CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(result.ocId))
  507. }
  508. NCManageDatabase.shared.clearDatabase(account: account, removeAccount: true)
  509. CCUtility.clearAllKeysEnd(toEnd: account)
  510. CCUtility.clearAllKeysPushNotification(account)
  511. CCUtility.setPassword(account, password: nil)
  512. settingAccount("", urlBase: "", user: "", userId: "", password: "")
  513. if wipe {
  514. let accounts = NCManageDatabase.shared.getAccounts()
  515. if accounts?.count ?? 0 > 0 {
  516. if let newAccount = accounts?.first {
  517. self.changeAccount(newAccount)
  518. }
  519. } else {
  520. openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
  521. }
  522. }
  523. }
  524. @objc func deleteAllAccounts() {
  525. let accounts = NCManageDatabase.shared.getAccounts()
  526. accounts?.forEach({ account in
  527. deleteAccount(account, wipe: true)
  528. })
  529. }
  530. @objc func changeAccount(_ account: String) {
  531. NCManageDatabase.shared.setAccountActive(account)
  532. if let tableAccount = NCManageDatabase.shared.getActiveAccount() {
  533. NCOperationQueue.shared.cancelAllQueue()
  534. NCNetworking.shared.cancelAllTask()
  535. settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
  536. }
  537. }
  538. func updateShareAccounts() -> Error? {
  539. guard let dirGroupApps = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupApps) else { return nil }
  540. let tableAccount = NCManageDatabase.shared.getAllAccount()
  541. var accounts = [NKShareAccounts.DataAccounts]()
  542. for account in tableAccount {
  543. let name = account.alias.isEmpty ? account.displayName : account.alias
  544. let userBaseUrl = account.user + "-" + (URL(string: account.urlBase)?.host ?? "")
  545. let avatarFileName = userBaseUrl + "-\(account.user).png"
  546. let pathAvatarFileName = String(CCUtility.getDirectoryUserData()) + "/" + avatarFileName
  547. let image = UIImage(contentsOfFile: pathAvatarFileName)
  548. accounts.append(NKShareAccounts.DataAccounts(withUrl: account.urlBase, user: account.user, name: name, image: image))
  549. }
  550. return NKShareAccounts().putShareAccounts(at: dirGroupApps, app: NCGlobal.shared.appScheme, dataAccounts: accounts)
  551. }
  552. // MARK: - Account Request
  553. func accountRequestChangeAccount(account: String) {
  554. changeAccount(account)
  555. }
  556. func requestAccount() {
  557. if isPasscodePresented() { return }
  558. if !CCUtility.getAccountRequest() { return }
  559. let accounts = NCManageDatabase.shared.getAllAccount()
  560. if accounts.count > 1 {
  561. if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
  562. vcAccountRequest.activeAccount = NCManageDatabase.shared.getActiveAccount()
  563. vcAccountRequest.accounts = accounts
  564. vcAccountRequest.enableTimerProgress = true
  565. vcAccountRequest.enableAddAccount = false
  566. vcAccountRequest.dismissDidEnterBackground = false
  567. vcAccountRequest.delegate = self
  568. let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height / 5)
  569. let numberCell = accounts.count
  570. let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
  571. let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height + 20)
  572. popup.backgroundAlpha = 0.8
  573. window?.rootViewController?.present(popup, animated: true)
  574. vcAccountRequest.startTimer()
  575. }
  576. }
  577. }
  578. // MARK: - Passcode
  579. func presentPasscode(completion: @escaping () -> Void) {
  580. let laContext = LAContext()
  581. var error: NSError?
  582. defer { self.requestAccount() }
  583. let presentedViewController = window?.rootViewController?.presentedViewController
  584. guard !account.isEmpty, CCUtility.isPasscodeAtStartEnabled(), !(presentedViewController is NCLoginNavigationController) else { return }
  585. // Make sure we have a privacy window (in case it's not enabled)
  586. showPrivacyProtectionWindow()
  587. let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: false)
  588. passcodeViewController.delegate = self
  589. passcodeViewController.keypadButtonShowLettering = false
  590. if CCUtility.getEnableTouchFaceID() && laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
  591. if error == nil {
  592. if laContext.biometryType == .faceID {
  593. passcodeViewController.biometryType = .faceID
  594. } else if laContext.biometryType == .touchID {
  595. passcodeViewController.biometryType = .touchID
  596. }
  597. passcodeViewController.allowBiometricValidation = true
  598. passcodeViewController.automaticallyPromptForBiometricValidation = false
  599. }
  600. }
  601. // show passcode on top of privacy window
  602. privacyProtectionWindow?.rootViewController?.present(passcodeViewController, animated: true, completion: {
  603. completion()
  604. })
  605. }
  606. func isPasscodePresented() -> Bool {
  607. return privacyProtectionWindow?.rootViewController?.presentedViewController is TOPasscodeViewController
  608. }
  609. func enableTouchFaceID() {
  610. guard !account.isEmpty,
  611. CCUtility.getEnableTouchFaceID(),
  612. CCUtility.isPasscodeAtStartEnabled(),
  613. let passcodeViewController = privacyProtectionWindow?.rootViewController?.presentedViewController as? TOPasscodeViewController
  614. else { return }
  615. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  616. LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: NCBrandOptions.shared.brand) { success, _ in
  617. if success {
  618. DispatchQueue.main.async {
  619. passcodeViewController.dismiss(animated: true) {
  620. self.hidePrivacyProtectionWindow()
  621. self.requestAccount()
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. func didInputCorrectPasscode(in passcodeViewController: TOPasscodeViewController) {
  629. DispatchQueue.main.async {
  630. passcodeViewController.dismiss(animated: true) {
  631. self.hidePrivacyProtectionWindow()
  632. self.requestAccount()
  633. }
  634. }
  635. }
  636. func passcodeViewController(_ passcodeViewController: TOPasscodeViewController, isCorrectCode code: String) -> Bool {
  637. return code == CCUtility.getPasscode()
  638. }
  639. func didPerformBiometricValidationRequest(in passcodeViewController: TOPasscodeViewController) {
  640. enableTouchFaceID()
  641. }
  642. // MARK: - Privacy Protection
  643. private func showPrivacyProtectionWindow() {
  644. guard privacyProtectionWindow == nil else {
  645. privacyProtectionWindow?.isHidden = false
  646. return
  647. }
  648. privacyProtectionWindow = UIWindow(frame: UIScreen.main.bounds)
  649. let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
  650. let initialViewController = storyboard.instantiateInitialViewController()
  651. self.privacyProtectionWindow?.rootViewController = initialViewController
  652. privacyProtectionWindow?.windowLevel = .alert + 1
  653. privacyProtectionWindow?.makeKeyAndVisible()
  654. }
  655. func hidePrivacyProtectionWindow() {
  656. guard !(privacyProtectionWindow?.rootViewController?.presentedViewController is TOPasscodeViewController) else { return }
  657. UIWindow.animate(withDuration: 0.25) {
  658. self.privacyProtectionWindow?.alpha = 0
  659. } completion: { _ in
  660. self.privacyProtectionWindow?.isHidden = true
  661. self.privacyProtectionWindow = nil
  662. }
  663. }
  664. // MARK: - Universal Links
  665. func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
  666. let applicationHandle = NCApplicationHandle()
  667. return applicationHandle.applicationOpenUserActivity(userActivity)
  668. }
  669. // MARK: - Scheme URL
  670. func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
  671. let scheme = url.scheme
  672. let action = url.host
  673. var fileName: String = ""
  674. var serverUrl: String = ""
  675. /*
  676. Example:
  677. nextcloud://open-action?action=create-voice-memo&&user=marinofaggiana&url=https://cloud.nextcloud.com
  678. */
  679. if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-action" {
  680. if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
  681. let queryItems = urlComponents.queryItems
  682. guard let actionScheme = CCUtility.value(forKey: "action", fromQueryItems: queryItems), let rootViewController = window?.rootViewController else { return false }
  683. guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
  684. guard let urlScheme = CCUtility.value(forKey: "url", fromQueryItems: queryItems) else { return false }
  685. if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
  686. let message = NSLocalizedString("_the_account_", comment: "") + " " + userScheme + NSLocalizedString("_of_", comment: "") + " " + urlScheme + " " + NSLocalizedString("_does_not_exist_", comment: "")
  687. let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
  688. alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
  689. window?.rootViewController?.present(alertController, animated: true, completion: { })
  690. return false
  691. }
  692. switch actionScheme {
  693. case NCGlobal.shared.actionUploadAsset:
  694. NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: rootViewController) { hasPermission in
  695. if hasPermission {NCPhotosPickerViewController(viewController: rootViewController, maxSelectedAssets: 0, singleSelectedMode: false)
  696. }
  697. }
  698. case NCGlobal.shared.actionScanDocument:
  699. NCDocumentCamera.shared.openScannerDocument(viewController: rootViewController)
  700. case NCGlobal.shared.actionTextDocument:
  701. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController(), let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account), let directEditingCreator = directEditingCreators.first(where: { $0.editor == NCGlobal.shared.editorText}) else { return false }
  702. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  703. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  704. viewController.editorId = NCGlobal.shared.editorText
  705. viewController.creatorId = directEditingCreator.identifier
  706. viewController.typeTemplate = NCGlobal.shared.templateDocument
  707. viewController.serverUrl = activeServerUrl
  708. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  709. rootViewController.present(navigationController, animated: true, completion: nil)
  710. case NCGlobal.shared.actionVoiceMemo:
  711. NCAskAuthorization.shared.askAuthorizationAudioRecord(viewController: rootViewController) { hasPermission in
  712. if hasPermission {
  713. let fileName = CCUtility.createFileNameDate(NSLocalizedString("_voice_memo_filename_", comment: ""), extension: "m4a")!
  714. let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as! NCAudioRecorderViewController
  715. viewController.delegate = self
  716. viewController.createRecorder(fileName: fileName)
  717. viewController.modalTransitionStyle = .crossDissolve
  718. viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  719. rootViewController.present(viewController, animated: true, completion: nil)
  720. }
  721. }
  722. default:
  723. print("No action")
  724. }
  725. }
  726. return true
  727. }
  728. /*
  729. Example:
  730. nextcloud://open-file?path=Talk/IMG_0000123.jpg&user=marinofaggiana&link=https://cloud.nextcloud.com/f/123
  731. */
  732. else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-file" {
  733. if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
  734. let queryItems = urlComponents.queryItems
  735. guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
  736. guard let pathScheme = CCUtility.value(forKey: "path", fromQueryItems: queryItems) else { return false }
  737. guard let linkScheme = CCUtility.value(forKey: "link", fromQueryItems: queryItems) else { return false }
  738. guard let matchedAccount = getMatchedAccount(userId: userScheme, url: linkScheme) else {
  739. guard let domain = URL(string: linkScheme)?.host else { return true }
  740. fileName = (pathScheme as NSString).lastPathComponent
  741. let message = String(format: NSLocalizedString("_account_not_available_", comment: ""), userScheme, domain, fileName)
  742. let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
  743. alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
  744. window?.rootViewController?.present(alertController, animated: true, completion: { })
  745. return false
  746. }
  747. let davFiles = NextcloudKit.shared.nkCommonInstance.dav + "/files/" + self.userId
  748. if pathScheme.contains("/") {
  749. fileName = (pathScheme as NSString).lastPathComponent
  750. serverUrl = matchedAccount.urlBase + "/" + davFiles + "/" + (pathScheme as NSString).deletingLastPathComponent
  751. } else {
  752. fileName = pathScheme
  753. serverUrl = matchedAccount.urlBase + "/" + davFiles
  754. }
  755. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  756. NCActionCenter.shared.openFileViewInFolder(serverUrl: serverUrl, fileNameBlink: nil, fileNameOpen: fileName)
  757. }
  758. }
  759. return true
  760. /*
  761. Example:
  762. nextcloud://open-and-switch-account?user=marinofaggiana&url=https://cloud.nextcloud.com
  763. */
  764. } else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-and-switch-account" {
  765. guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return false }
  766. let queryItems = urlComponents.queryItems
  767. guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
  768. guard let urlScheme = CCUtility.value(forKey: "url", fromQueryItems: queryItems) else { return false }
  769. // If the account doesn't exist, return false which will open the app without switching
  770. if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
  771. return false
  772. }
  773. // Otherwise open the app and switch accounts
  774. return true
  775. } else {
  776. let applicationHandle = NCApplicationHandle()
  777. let isHandled = applicationHandle.applicationOpenURL(url)
  778. if isHandled {
  779. return true
  780. } else {
  781. app.open(url)
  782. return true
  783. }
  784. }
  785. }
  786. func getMatchedAccount(userId: String, url: String) -> tableAccount? {
  787. if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
  788. let urlBase = URL(string: activeAccount.urlBase)
  789. if url.contains(urlBase?.host ?? "") && userId == activeAccount.userId {
  790. return activeAccount
  791. } else {
  792. let accounts = NCManageDatabase.shared.getAllAccount()
  793. for account in accounts {
  794. let urlBase = URL(string: account.urlBase)
  795. if url.contains(urlBase?.host ?? "") && userId == account.userId {
  796. changeAccount(account.account)
  797. return account
  798. }
  799. }
  800. }
  801. }
  802. return nil
  803. }
  804. }
  805. // MARK: - NCAudioRecorder ViewController Delegate
  806. extension AppDelegate: NCAudioRecorderViewControllerDelegate {
  807. func didFinishRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
  808. guard
  809. let navigationController = UIStoryboard(name: "NCCreateFormUploadVoiceNote", bundle: nil).instantiateInitialViewController() as? UINavigationController,
  810. let viewController = navigationController.topViewController as? NCCreateFormUploadVoiceNote
  811. else { return }
  812. navigationController.modalPresentationStyle = .formSheet
  813. viewController.setup(serverUrl: activeServerUrl, fileNamePath: NSTemporaryDirectory() + fileName, fileName: fileName)
  814. window?.rootViewController?.present(navigationController, animated: true)
  815. }
  816. func didFinishWithoutRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
  817. }
  818. }
  819. extension AppDelegate: NCCreateFormUploadConflictDelegate {
  820. func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
  821. guard let metadatas = metadatas, !metadatas.isEmpty else { return }
  822. NCNetworkingProcessUpload.shared.createProcessUploads(metadatas: metadatas) { _ in }
  823. }
  824. }