AppDelegate.m 45 KB

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