AppDelegate.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. //
  2. // AppDelegate.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  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 "AppDelegate.h"
  24. #import "CCGraphics.h"
  25. #import "NCBridgeSwift.h"
  26. #import "NCAutoUpload.h"
  27. #import "NCPushNotificationEncryption.h"
  28. #import <QuartzCore/QuartzCore.h>
  29. @import Firebase;
  30. @class NCViewerRichdocument;
  31. @interface AppDelegate() <TOPasscodeViewControllerDelegate>
  32. @end
  33. @implementation AppDelegate
  34. + (void)initialize
  35. {
  36. [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent": [CCUtility getUserAgent]}];
  37. }
  38. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  39. {
  40. BOOL isSimulatorOrTestFlight = [[NCUtility shared] isSimulatorOrTestFlight];
  41. if (![CCUtility getDisableCrashservice] && NCBrandOptions.sharedInstance.disable_crash_service == false) {
  42. [FIRApp configure];
  43. }
  44. [CCUtility createDirectoryStandard];
  45. [CCUtility emptyTemporaryDirectory];
  46. // Networking
  47. [[NCCommunicationCommon shared] setupWithDelegate:[NCNetworking shared]];
  48. [[NCCommunicationCommon shared] setupWithUserAgent:[CCUtility getUserAgent]];
  49. NSInteger logLevel = [CCUtility getLogLevel];
  50. [[NCCommunicationCommon shared] setFileLogWithLevel:logLevel];
  51. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  52. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  53. if (isSimulatorOrTestFlight) {
  54. [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Start session with level %lu %@ (Simulator / TestFlight)", (unsigned long)logLevel, versionNextcloudiOS]];
  55. } else {
  56. [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Start session with level %lu %@", (unsigned long)logLevel, versionNextcloudiOS]];
  57. }
  58. //
  59. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:k_notificationCenter_initializeMain object:nil];
  60. // Set account, if no exists clear all
  61. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  62. if (tableAccount == nil) {
  63. // remove all the keys Chain
  64. [CCUtility deleteAllChainStore];
  65. // remove all the App group key
  66. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  67. } else {
  68. // FIX 3.0.5 lost urlbase
  69. if (tableAccount.urlBase.length == 0) {
  70. NSString *user = [tableAccount.user stringByAppendingString:@" "];
  71. NSString *urlBase = [tableAccount.account stringByReplacingOccurrencesOfString:user withString:@""];
  72. tableAccount.urlBase = urlBase;
  73. [[NCManageDatabase sharedInstance] updateAccount:tableAccount];
  74. tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  75. }
  76. [self settingAccount:tableAccount.account urlBase:tableAccount.urlBase user:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account]];
  77. }
  78. // UserDefaults
  79. self.ncUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[NCBrandOptions sharedInstance].capabilitiesGroups];
  80. // Background Fetch
  81. [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
  82. self.listProgressMetadata = [NSMutableDictionary new];
  83. self.listFilesVC = [NSMutableDictionary new];
  84. self.listFavoriteVC = [NSMutableDictionary new];
  85. self.listOfflineVC = [NSMutableDictionary new];
  86. // Push Notification
  87. [application registerForRemoteNotifications];
  88. // Display notification
  89. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  90. UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  91. [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { }];
  92. //AV Session
  93. [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
  94. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  95. // Start Timer
  96. self.timerUpdateApplicationIconBadgeNumber = [NSTimer scheduledTimerWithTimeInterval:k_timerUpdateApplicationIconBadgeNumber target:self selector:@selector(updateApplicationIconBadgeNumber) userInfo:nil repeats:YES];
  97. [self startTimerErrorNetworking];
  98. // Store review
  99. if ([[NCUtility shared] isSimulatorOrTestFlight] == false) {
  100. NCStoreReview *review = [NCStoreReview new];
  101. [review incrementAppRuns];
  102. [review showStoreReview];
  103. }
  104. // Detect Dark mode
  105. if (@available(iOS 13.0, *)) {
  106. if ([CCUtility getDarkModeDetect]) {
  107. if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
  108. [CCUtility setDarkMode:YES];
  109. } else {
  110. [CCUtility setDarkMode:NO];
  111. }
  112. }
  113. }
  114. if ([NCBrandOptions sharedInstance].disable_intro) {
  115. [CCUtility setIntro:YES];
  116. if (self.account.length == 0) {
  117. [self openLoginView:nil selector:k_intro_login openLoginWeb:false];
  118. }
  119. } else {
  120. if ([CCUtility getIntro] == NO) {
  121. UIViewController *introViewController = [[UIStoryboard storyboardWithName:@"NCIntro" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
  122. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: introViewController];
  123. self.window.rootViewController = navController;
  124. [self.window makeKeyAndVisible];
  125. }
  126. }
  127. // init home
  128. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  129. // Passcode
  130. dispatch_async(dispatch_get_main_queue(), ^{
  131. [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
  132. });
  133. // Auto upload
  134. self.networkingAutoUpload = [NCNetworkingAutoUpload new];
  135. return YES;
  136. }
  137. //
  138. // L' applicazione si dimetterà dallo stato di attivo
  139. //
  140. - (void)applicationWillResignActive:(UIApplication *)application
  141. {
  142. if (self.account.length == 0) { return; }
  143. // Dismiss FileViewInFolder
  144. if (self.activeFileViewInFolder != nil ) {
  145. [self.activeFileViewInFolder dismissViewControllerAnimated:false completion:^{
  146. self.activeFileViewInFolder = nil;
  147. }];
  148. }
  149. [self updateApplicationIconBadgeNumber];
  150. }
  151. //
  152. // L' applicazione entrerà in primo piano (attivo solo dopo il background)
  153. //
  154. - (void)applicationWillEnterForeground:(UIApplication *)application
  155. {
  156. if (self.account.length == 0) { return; }
  157. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_applicationWillEnterForeground object:nil];
  158. // Request Passcode
  159. [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
  160. // Initialize Auto upload
  161. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  162. // Read active directory
  163. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_reloadDataSourceNetworkForced object:nil];
  164. // Required unsubscribing / subscribing
  165. [self pushNotification];
  166. // RichDocument
  167. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_richdocumentGrabFocus object:nil];
  168. // Request Service Server Nextcloud
  169. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  170. [[NCService shared] startRequestServicesServer];
  171. });
  172. }
  173. //
  174. // L' applicazione entrerà in primo piano (attivo sempre)
  175. //
  176. - (void)applicationDidBecomeActive:(UIApplication *)application
  177. {
  178. if (self.account.length == 0) { return; }
  179. // Brand
  180. #if defined(HC)
  181. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  182. if (account.hcIsTrial == true || account.hcTrialExpired == true || account.hcNextGroupExpirationGroupExpired == true) {
  183. HCTrial *vc = [[UIStoryboard storyboardWithName:@"HCTrial" bundle:nil] instantiateInitialViewController];
  184. vc.account = account;
  185. [self.window.rootViewController presentViewController:vc animated:YES completion:nil];
  186. }
  187. #endif
  188. [[NCNetworking shared] verifyUploadZombie];
  189. }
  190. //
  191. // L' applicazione è entrata nello sfondo
  192. //
  193. - (void)applicationDidEnterBackground:(UIApplication *)application
  194. {
  195. if (self.account.length == 0) { return; }
  196. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_applicationDidEnterBackground object:nil];
  197. [self passcodeWithAutomaticallyPromptForBiometricValidation:false];
  198. }
  199. //
  200. // L'applicazione terminerà
  201. //
  202. - (void)applicationWillTerminate:(UIApplication *)application
  203. {
  204. [[NCCommunicationCommon shared] writeLog:@"bye bye"];
  205. }
  206. // NotificationCenter
  207. - (void)initializeMain:(NSNotification *)notification
  208. {
  209. if (self.account.length == 0) { return; }
  210. // Clear error certificate
  211. [CCUtility setCertificateError:self.account error:NO];
  212. // Setting Theming
  213. [[NCBrandColor sharedInstance] settingThemingColor];
  214. // close detail
  215. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_menuDetailClose object:nil];
  216. // Not Photos Video in library ? then align and Init Auto Upload
  217. NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", self.account]];
  218. if ([recordsPhotoLibrary count] == 0) {
  219. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  220. }
  221. // Start Auto Upload
  222. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  223. // Start services
  224. [[NCService shared] startRequestServicesServer];
  225. // Registeration push notification
  226. [self pushNotification];
  227. // Registeration domain File Provider
  228. //FileProviderDomain *fileProviderDomain = [FileProviderDomain new];
  229. //[fileProviderDomain removeAllDomains];
  230. //[fileProviderDomain registerDomains];
  231. [[NCCommunicationCommon shared] writeLog:@"initialize Main"];
  232. }
  233. #pragma --------------------------------------------------------------------------------------------
  234. #pragma mark ===== Login / checkErrorNetworking =====
  235. #pragma --------------------------------------------------------------------------------------------
  236. - (void)checkErrorNetworking
  237. {
  238. if (self.account.length == 0) { return; }
  239. // check unauthorized server (401)
  240. if ([CCUtility getPassword:self.account].length == 0) {
  241. [self openLoginView:self.window.rootViewController selector:k_intro_login openLoginWeb:true];
  242. }
  243. // check certificate untrusted (-1202)
  244. if ([CCUtility getCertificateError:self.account]) {
  245. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_ssl_certificate_untrusted_", nil) message:NSLocalizedString(@"_connect_server_anyway_", nil) preferredStyle:UIAlertControllerStyleAlert];
  246. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  247. [[NCNetworking shared] wrtiteCertificateWithDirectoryCertificate:[CCUtility getDirectoryCerificates]];
  248. [self startTimerErrorNetworking];
  249. }]];
  250. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_no_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  251. [self startTimerErrorNetworking];
  252. }]];
  253. [self.window.rootViewController presentViewController:alertController animated:YES completion:^{
  254. // Stop timer error network
  255. [self.timerErrorNetworking invalidate];
  256. }];
  257. }
  258. }
  259. - (void)openLoginView:(UIViewController *)viewController selector:(NSInteger)selector openLoginWeb:(BOOL)openLoginWeb
  260. {
  261. // use appConfig [MDM]
  262. if ([NCBrandOptions sharedInstance].use_configuration) {
  263. if (!(_appConfigView.isViewLoaded && _appConfigView.view.window)) {
  264. self.appConfigView = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCAppConfigView"];
  265. [self showLoginViewController:self.appConfigView forContext:viewController];
  266. }
  267. return;
  268. }
  269. // only for personalized LoginWeb [customer]
  270. if ([NCBrandOptions sharedInstance].use_login_web_personalized) {
  271. if (!(_activeLoginWeb.isViewLoaded && _activeLoginWeb.view.window)) {
  272. self.activeLoginWeb = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCLoginWeb"];
  273. self.activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginBaseUrl];
  274. [self showLoginViewController:self.activeLoginWeb forContext:viewController];
  275. }
  276. return;
  277. }
  278. // normal login
  279. if (selector == k_intro_signup) {
  280. if (!(_activeLoginWeb.isViewLoaded && _activeLoginWeb.view.window)) {
  281. self.activeLoginWeb = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCLoginWeb"];
  282. if (selector == k_intro_signup) {
  283. self.activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] linkloginPreferredProviders];
  284. } else {
  285. self.activeLoginWeb.urlBase = self.urlBase;
  286. }
  287. [self showLoginViewController:self.activeLoginWeb forContext:viewController];
  288. }
  289. } else if ([NCBrandOptions sharedInstance].disable_intro && [NCBrandOptions sharedInstance].disable_request_login_url) {
  290. self.activeLoginWeb = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCLoginWeb"];
  291. self.activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginBaseUrl];
  292. [self showLoginViewController:self.activeLoginWeb forContext:viewController];
  293. } else if (openLoginWeb) {
  294. if (!(_activeLoginWeb.isViewLoaded && _activeLoginWeb.view.window)) {
  295. self.activeLoginWeb = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCLoginWeb"];
  296. self.activeLoginWeb.urlBase = self.urlBase;
  297. [self showLoginViewController:self.activeLoginWeb forContext:viewController];
  298. }
  299. } else {
  300. if (!(_activeLogin.isViewLoaded && _activeLogin.view.window)) {
  301. _activeLogin = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
  302. [self showLoginViewController:_activeLogin forContext:viewController];
  303. }
  304. }
  305. }
  306. -(void)showLoginViewController:(UIViewController *)viewController forContext:(UIViewController *)contextViewController
  307. {
  308. if (contextViewController == NULL) {
  309. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  310. navigationController.navigationBar.barStyle = UIBarStyleBlack;
  311. navigationController.navigationBar.tintColor = NCBrandColor.sharedInstance.customerText;
  312. navigationController.navigationBar.barTintColor = NCBrandColor.sharedInstance.customer;
  313. [navigationController.navigationBar setTranslucent:false];
  314. self.window.rootViewController = navigationController;
  315. [self.window makeKeyAndVisible];
  316. } else if ([contextViewController isKindOfClass:[UINavigationController class]]) {
  317. UINavigationController *navigationController = ((UINavigationController *)contextViewController);
  318. [navigationController pushViewController:viewController animated:true];
  319. } else {
  320. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  321. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  322. navigationController.navigationBar.barStyle = UIBarStyleBlack;
  323. navigationController.navigationBar.tintColor = NCBrandColor.sharedInstance.customerText;
  324. navigationController.navigationBar.barTintColor = NCBrandColor.sharedInstance.customer;
  325. [navigationController.navigationBar setTranslucent:false];
  326. [contextViewController presentViewController:navigationController animated:true completion:nil];
  327. }
  328. }
  329. - (void)startTimerErrorNetworking
  330. {
  331. self.timerErrorNetworking = [NSTimer scheduledTimerWithTimeInterval:k_timerErrorNetworking target:self selector:@selector(checkErrorNetworking) userInfo:nil repeats:YES];
  332. }
  333. #pragma --------------------------------------------------------------------------------------------
  334. #pragma mark ===== Account & Communication =====
  335. #pragma --------------------------------------------------------------------------------------------
  336. - (void)settingAccount:(NSString *)account urlBase:(NSString *)urlBase user:(NSString *)user userID:(NSString *)userID password:(NSString *)password
  337. {
  338. self.account = account;
  339. self.urlBase = urlBase;
  340. self.user = user;
  341. self.userID = userID;
  342. self.password = password;
  343. (void)[NCNetworkingNotificationCenter shared];
  344. [[NCCommunicationCommon shared] setupWithAccount:account user:user userId:userID password:password urlBase:urlBase];
  345. [self settingSetupCommunication:account];
  346. }
  347. - (void)deleteAccount:(NSString *)account wipe:(BOOL)wipe
  348. {
  349. // Push Notification
  350. tableAccount *accountPN = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
  351. [self unsubscribingNextcloudServerPushNotification:accountPN.account urlBase:accountPN.urlBase user:accountPN.user withSubscribing:false];
  352. [self settingAccount:nil urlBase:nil user:nil userID:nil password:nil];
  353. /* DELETE ALL FILES LOCAL FS */
  354. NSArray *results = [[NCManageDatabase sharedInstance] getTableLocalFilesWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account] sorted:@"ocId" ascending:NO];
  355. for (tableLocalFile *result in results) {
  356. [CCUtility removeFileAtPath:[CCUtility getDirectoryProviderStorageOcId:result.ocId]];
  357. }
  358. // Clear database
  359. [[NCManageDatabase sharedInstance] clearDatabaseWithAccount:account removeAccount:true];
  360. [CCUtility clearAllKeysEndToEnd:account];
  361. [CCUtility clearAllKeysPushNotification:account];
  362. [CCUtility setCertificateError:account error:false];
  363. [CCUtility setPassword:account password:nil];
  364. if (wipe) {
  365. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  366. if ([listAccount count] > 0) {
  367. NSString *newAccount = listAccount[0];
  368. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:newAccount];
  369. [self settingAccount:newAccount urlBase:tableAccount.urlBase user:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account]];
  370. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  371. } else {
  372. [self openLoginView:self.window.rootViewController selector:k_intro_login openLoginWeb:false];
  373. }
  374. }
  375. }
  376. - (void)settingSetupCommunication:(NSString *)account
  377. {
  378. NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
  379. if (serverVersionMajor > 0) {
  380. [[NCCommunicationCommon shared] setupWithNextcloudVersion:serverVersionMajor];
  381. }
  382. [[NCCommunicationCommon shared] setupWithWebDav:[[NCUtility shared] getWebDAVWithAccount:account]];
  383. [[NCCommunicationCommon shared] setupWithDav:[[NCUtility shared] getDAV]];
  384. }
  385. #pragma --------------------------------------------------------------------------------------------
  386. #pragma mark ===== Push Notifications =====
  387. #pragma --------------------------------------------------------------------------------------------
  388. - (void)pushNotification
  389. {
  390. if (self.account.length == 0 || self.pushKitToken.length == 0) { return; }
  391. for (tableAccount *result in [[NCManageDatabase sharedInstance] getAllAccount]) {
  392. NSString *token = [CCUtility getPushNotificationToken:result.account];
  393. if (![token isEqualToString:self.pushKitToken]) {
  394. if (token != nil) {
  395. // unsubscribing + subscribing
  396. [self unsubscribingNextcloudServerPushNotification:result.account urlBase:result.urlBase user:result.user withSubscribing:true];
  397. } else {
  398. [self subscribingNextcloudServerPushNotification:result.account urlBase:result.urlBase user:result.user];
  399. }
  400. }
  401. }
  402. }
  403. - (void)subscribingNextcloudServerPushNotification:(NSString *)account urlBase:(NSString *)urlBase user:(NSString *)user
  404. {
  405. if (self.account.length == 0 || self.pushKitToken.length == 0) { return; }
  406. [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair:account];
  407. NSString *pushTokenHash = [[NCEndToEndEncryption sharedManager] createSHA512:self.pushKitToken];
  408. NSData *pushPublicKey = [CCUtility getPushNotificationPublicKey:account];
  409. NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
  410. NSString *proxyServerPath = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
  411. [[NCCommunication shared] subscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSInteger errorCode, NSString *errorDescription) {
  412. if (errorCode == 0) {
  413. NSString *userAgent = [NSString stringWithFormat:@"%@ (Strict VoIP)", [CCUtility getUserAgent]];
  414. [[NCCommunication shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent completionHandler:^(NSInteger errorCode, NSString *errorDescription) {
  415. if (errorCode == 0) {
  416. [[NCCommunicationCommon shared] writeLog:@"Subscribed to Push Notification server & proxy successfully"];
  417. [CCUtility setPushNotificationToken:account token:self.pushKitToken];
  418. [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:deviceIdentifier];
  419. [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:signature];
  420. [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:publicKey];
  421. }
  422. }];
  423. }
  424. }];
  425. }
  426. - (void)unsubscribingNextcloudServerPushNotification:(NSString *)account urlBase:(NSString *)urlBase user:(NSString *)user withSubscribing:(BOOL)subscribing
  427. {
  428. if (self.account.length == 0) { return; }
  429. NSString *deviceIdentifier = [CCUtility getPushNotificationDeviceIdentifier:account];
  430. NSString *signature = [CCUtility getPushNotificationDeviceIdentifierSignature:account];
  431. NSString *publicKey = [CCUtility getPushNotificationSubscribingPublicKey:account];
  432. [[NCCommunication shared] unsubscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDescription) {
  433. if (errorCode == 0) {
  434. NSString *userAgent = [NSString stringWithFormat:@"%@ (Strict VoIP)", [CCUtility getUserAgent]];
  435. NSString *proxyServerPath = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
  436. [[NCCommunication shared] unsubscribingPushProxyWithProxyServerUrl:proxyServerPath deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent completionHandler:^(NSInteger errorCode, NSString *errorDescription) {
  437. if (errorCode == 0) {
  438. [[NCCommunicationCommon shared] writeLog:@"Unsubscribed to Push Notification server & proxy successfully."];
  439. [CCUtility setPushNotificationPublicKey:account data:nil];
  440. [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:nil];
  441. [CCUtility setPushNotificationPrivateKey:account data:nil];
  442. [CCUtility setPushNotificationToken:account token:nil];
  443. [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:nil];
  444. [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:nil];
  445. if (self.pushKitToken != nil && subscribing) {
  446. [self subscribingNextcloudServerPushNotification:account urlBase:urlBase user:user];
  447. }
  448. }
  449. }];
  450. }
  451. }];
  452. }
  453. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
  454. {
  455. //Called when a notification is delivered to a foreground app.
  456. completionHandler(UNNotificationPresentationOptionAlert);
  457. }
  458. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler
  459. {
  460. completionHandler();
  461. }
  462. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  463. {
  464. self.pushKitToken = [self stringWithDeviceToken:deviceToken];
  465. [self pushNotification];
  466. }
  467. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  468. {
  469. NSString *message = [userInfo objectForKey:@"subject"];
  470. if (message) {
  471. NSArray *results = [[NCManageDatabase sharedInstance] getAllAccount];
  472. for (tableAccount *result in results) {
  473. if ([CCUtility getPushNotificationPrivateKey:result.account]) {
  474. NSData *decryptionKey = [CCUtility getPushNotificationPrivateKey:result.account];
  475. NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:decryptionKey];
  476. if (decryptedMessage) {
  477. NSData *data = [decryptedMessage dataUsingEncoding:NSUTF8StringEncoding];
  478. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  479. NSInteger nid = [[json objectForKey:@"nid"] integerValue];
  480. BOOL delete = [[json objectForKey:@"delete"] boolValue];
  481. BOOL deleteAll = [[json objectForKey:@"delete-all"] boolValue];
  482. if (delete) {
  483. [self removeNotificationWithNotificationId:nid usingDecryptionKey:decryptionKey];
  484. } else if (deleteAll) {
  485. [self cleanAllNotifications];
  486. }
  487. }
  488. }
  489. }
  490. }
  491. completionHandler(UIBackgroundFetchResultNoData);
  492. }
  493. - (void)cleanAllNotifications
  494. {
  495. [[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
  496. }
  497. - (void)removeNotificationWithNotificationId:(NSInteger)notificationId usingDecryptionKey:(NSData *)key
  498. {
  499. // Check in pending notifications
  500. [[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
  501. for (UNNotificationRequest *notificationRequest in requests) {
  502. NSString *message = [notificationRequest.content.userInfo objectForKey:@"subject"];
  503. NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:key];
  504. if (decryptedMessage) {
  505. NSData *data = [decryptedMessage dataUsingEncoding:NSUTF8StringEncoding];
  506. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  507. NSInteger nid = [[json objectForKey:@"nid"] integerValue];
  508. if (nid == notificationId) {
  509. [[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[notificationRequest.identifier]];
  510. }
  511. }
  512. }
  513. }];
  514. // Check in delivered notifications
  515. [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
  516. for (UNNotification *notification in notifications) {
  517. NSString *message = [notification.request.content.userInfo objectForKey:@"subject"];
  518. NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:key];
  519. if (decryptedMessage) {
  520. NSData *data = [decryptedMessage dataUsingEncoding:NSUTF8StringEncoding];
  521. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  522. NSInteger nid = [[json objectForKey:@"nid"] integerValue];
  523. if (nid == notificationId) {
  524. [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[notification.request.identifier]];
  525. }
  526. }
  527. }
  528. }];
  529. }
  530. - (NSString *)stringWithDeviceToken:(NSData *)deviceToken
  531. {
  532. const char *data = [deviceToken bytes];
  533. NSMutableString *token = [NSMutableString string];
  534. for (NSUInteger i = 0; i < [deviceToken length]; i++) {
  535. [token appendFormat:@"%02.2hhX", data[i]];
  536. }
  537. return [token copy];
  538. }
  539. #pragma --------------------------------------------------------------------------------------------
  540. #pragma mark ===== ApplicationIconBadgeNumber =====
  541. #pragma --------------------------------------------------------------------------------------------
  542. - (void)updateApplicationIconBadgeNumber
  543. {
  544. if (self.account.length == 0) { return; }
  545. NSInteger counterDownload = [[NCOperationQueue shared] downloadCount];
  546. NSInteger counterUpload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"status == %d OR status == %d OR status == %d", k_metadataStatusWaitUpload, k_metadataStatusInUpload, k_metadataStatusUploading]].count;
  547. NSInteger total = counterDownload + counterUpload;
  548. [UIApplication sharedApplication].applicationIconBadgeNumber = total;
  549. UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
  550. if ([tabBarController isKindOfClass:[UITabBarController class]]) {
  551. UITabBarItem *tabBarItem = [tabBarController.tabBar.items objectAtIndex:0];
  552. if (total > 0) {
  553. [tabBarItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
  554. } else {
  555. [tabBarItem setBadgeValue:nil];
  556. }
  557. }
  558. }
  559. #pragma --------------------------------------------------------------------------------------------
  560. #pragma mark ===== Fetch =====
  561. #pragma --------------------------------------------------------------------------------------------
  562. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  563. {
  564. if (self.account.length == 0) {
  565. completionHandler(UIBackgroundFetchResultNoData);
  566. return;
  567. }
  568. [[NCCommunicationCommon shared] writeLog:@"Start perform Fetch With Completion Handler"];
  569. // Verify new photo
  570. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  571. // after 20 sec
  572. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  573. [[NCCommunicationCommon shared] writeLog:@"End 20 sec. perform Fetch With Completion Handler"];
  574. completionHandler(UIBackgroundFetchResultNoData);
  575. });
  576. }
  577. #pragma --------------------------------------------------------------------------------------------
  578. #pragma mark ===== Operation Networking & Session =====
  579. #pragma --------------------------------------------------------------------------------------------
  580. //
  581. // Method called by the system when all the background task has end
  582. //
  583. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
  584. {
  585. [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Start handle Events For Background URLSession: %@", identifier]];
  586. [self updateApplicationIconBadgeNumber];
  587. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  588. self.backgroundSessionCompletionHandler = completionHandler;
  589. void (^completionHandler)() = self.backgroundSessionCompletionHandler;
  590. self.backgroundSessionCompletionHandler = nil;
  591. completionHandler();
  592. });
  593. }
  594. #pragma --------------------------------------------------------------------------------------------
  595. #pragma mark ===== OpenURL =====
  596. #pragma --------------------------------------------------------------------------------------------
  597. // Method called from iOS system to send a file from other app.
  598. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
  599. {
  600. if (self.account.length == 0) { return YES; }
  601. NSString *scheme = url.scheme;
  602. NSString *fileName;
  603. NSString *serverUrl;
  604. if ([scheme isEqualToString:@"nextcloud"]) {
  605. NSString *action = url.host;
  606. if ([action isEqualToString:@"open-file"]) {
  607. NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
  608. NSArray *queryItems = urlComponents.queryItems;
  609. NSString *user = [CCUtility valueForKey:@"user" fromQueryItems:queryItems];
  610. NSString *path = [CCUtility valueForKey:@"path" fromQueryItems:queryItems];
  611. NSString *link = [CCUtility valueForKey:@"link" fromQueryItems:queryItems];
  612. tableAccount *matchedAccount = nil;
  613. // verify parameter
  614. if (user.length == 0 || path.length == 0 || [[NSURL URLWithString:link] host].length == 0) {
  615. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_parameter_schema_", nil) preferredStyle:UIAlertControllerStyleAlert];
  616. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  617. [alertController addAction:okAction];
  618. [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
  619. } else {
  620. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  621. if (account) {
  622. NSURL *accountURL = [NSURL URLWithString:account.urlBase];
  623. NSString *accountUser = account.user;
  624. if ([link containsString:accountURL.host] && [user isEqualToString:accountUser]) {
  625. matchedAccount = account;
  626. } else {
  627. NSArray *accounts = [[NCManageDatabase sharedInstance] getAllAccount];
  628. for (tableAccount *account in accounts) {
  629. NSURL *accountURL = [NSURL URLWithString:account.urlBase];
  630. NSString *accountUser = account.user;
  631. if ([link containsString:accountURL.host] && [user isEqualToString:accountUser]) {
  632. matchedAccount = [[NCManageDatabase sharedInstance] setAccountActive:account.account];
  633. [self settingAccount:matchedAccount.account urlBase:matchedAccount.urlBase user:matchedAccount.user userID:matchedAccount.userID password:[CCUtility getPassword:matchedAccount.account]];
  634. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  635. }
  636. }
  637. }
  638. if (matchedAccount) {
  639. NSString *webDAV = [[NCUtility shared] getWebDAVWithAccount:self.account];
  640. if ([path containsString:@"/"]) {
  641. fileName = [path lastPathComponent];
  642. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", matchedAccount.urlBase, webDAV, [path stringByDeletingLastPathComponent]];
  643. } else {
  644. fileName = path;
  645. serverUrl = [NSString stringWithFormat:@"%@/%@", matchedAccount.urlBase, webDAV];
  646. }
  647. [[NCCollectionCommon shared] openFileViewInFolderWithServerUrl:serverUrl fileName:fileName];
  648. } else {
  649. NSString *domain = [[NSURL URLWithString:link] host];
  650. NSString *fileName = [path lastPathComponent];
  651. NSString *message = [NSString stringWithFormat:NSLocalizedString(@"_account_not_available_", nil), user, domain, fileName];
  652. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_info_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  653. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  654. [alertController addAction:okAction];
  655. [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
  656. }
  657. }
  658. }
  659. }
  660. return YES;
  661. }
  662. NSError *error;
  663. NSLog(@"[LOG] the path is: %@", url.path);
  664. NSArray *splitedUrl = [url.path componentsSeparatedByString:@"/"];
  665. self.fileNameUpload = [NSString stringWithFormat:@"%@",[splitedUrl objectAtIndex:([splitedUrl count]-1)]];
  666. if (self.account) {
  667. [[NSFileManager defaultManager]removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:nil];
  668. [[NSFileManager defaultManager]moveItemAtPath:url.path toPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:&error];
  669. if (error == nil) {
  670. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  671. UIViewController *uploadNavigationViewController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
  672. [self.window.rootViewController presentViewController:uploadNavigationViewController animated:YES completion:nil];
  673. });
  674. }
  675. }
  676. return YES;
  677. }
  678. #pragma --------------------------------------------------------------------------------------------
  679. #pragma mark ===== Passcode + Delegate =====
  680. #pragma --------------------------------------------------------------------------------------------
  681. - (void)passcodeWithAutomaticallyPromptForBiometricValidation:(BOOL)automaticallyPromptForBiometricValidation
  682. {
  683. LAContext *laContext = [LAContext new];
  684. NSError *error;
  685. BOOL isBiometryAvailable = false;
  686. if ([[CCUtility getPasscode] length] == 0 || [self.account length] == 0 || [CCUtility getNotPasscodeAtStart]) return;
  687. if (self.passcodeViewController == nil) {
  688. self.passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentLight passcodeType:TOPasscodeTypeSixDigits];
  689. if (@available(iOS 13.0, *)) {
  690. if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
  691. self.passcodeViewController.style = TOPasscodeViewStyleTranslucentDark;
  692. }
  693. }
  694. self.passcodeViewController.delegate = self;
  695. self.passcodeViewController.keypadButtonShowLettering = false;
  696. if (CCUtility.getEnableTouchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
  697. if (error == NULL) {
  698. if (laContext.biometryType == LABiometryTypeFaceID) {
  699. self.passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
  700. self.passcodeViewController.allowBiometricValidation = true;
  701. isBiometryAvailable = true;
  702. } else if (laContext.biometryType == LABiometryTypeTouchID) {
  703. self.passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
  704. self.passcodeViewController.allowBiometricValidation = true;
  705. isBiometryAvailable = true;
  706. } else {
  707. isBiometryAvailable = false;
  708. NSLog(@"No Biometric support");
  709. }
  710. }
  711. }
  712. [self.window.rootViewController presentViewController:self.passcodeViewController animated:YES completion:^{
  713. [self enableTouchFaceID:automaticallyPromptForBiometricValidation];
  714. }];
  715. } else {
  716. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  717. [self enableTouchFaceID:automaticallyPromptForBiometricValidation];
  718. });
  719. }
  720. }
  721. - (void)didInputCorrectPasscodeInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  722. {
  723. [passcodeViewController dismissViewControllerAnimated:YES completion:^{
  724. self.passcodeViewController = nil;
  725. }];
  726. }
  727. - (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
  728. {
  729. return [code isEqualToString:[CCUtility getPasscode]];
  730. }
  731. - (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  732. {
  733. [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions sharedInstance] brand] reply:^(BOOL success, NSError * _Nullable error) {
  734. if (success) {
  735. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  736. [passcodeViewController dismissViewControllerAnimated:YES completion:^{
  737. self.passcodeViewController = nil;
  738. }];
  739. });
  740. }
  741. }];
  742. }
  743. - (void)enableTouchFaceID:(BOOL)automaticallyPromptForBiometricValidation
  744. {
  745. if (CCUtility.getEnableTouchFaceID && automaticallyPromptForBiometricValidation && self.passcodeViewController.view.window) {
  746. [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions sharedInstance] brand] reply:^(BOOL success, NSError * _Nullable error) {
  747. if (success) {
  748. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  749. [self.passcodeViewController dismissViewControllerAnimated:YES completion:^{
  750. self.passcodeViewController = nil;
  751. }];
  752. });
  753. }
  754. }];
  755. }
  756. }
  757. @end