AppDelegate.m 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. //
  2. // AppDelegate.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 "iRate.h"
  25. #import "AFURLSessionManager.h"
  26. #import "CCNetworking.h"
  27. #import "CCCoreData.h"
  28. #import "CCCrypto.h"
  29. #import "CCManageAsset.h"
  30. #import "CCGraphics.h"
  31. #import "CCPhotosCameraUpload.h"
  32. #import "CCSynchronize.h"
  33. #import "CCMain.h"
  34. #import "CCDetail.h"
  35. #import "Firebase.h"
  36. #ifdef CUSTOM_BUILD
  37. #import "CustomSwift.h"
  38. #else
  39. #import "Nextcloud-Swift.h"
  40. #endif
  41. @interface AppDelegate () <UNUserNotificationCenterDelegate, FIRMessagingDelegate>
  42. {
  43. }
  44. @end
  45. @implementation AppDelegate
  46. + (void)initialize
  47. {
  48. [iRate sharedInstance].daysUntilPrompt = 10;
  49. [iRate sharedInstance].usesUntilPrompt = 10;
  50. [iRate sharedInstance].promptForNewVersionIfUserRated = true;
  51. //enable preview mode
  52. //[iRate sharedInstance].previewMode = YES;
  53. }
  54. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  55. {
  56. // Brand
  57. if (k_option_use_firebase) {
  58. /*
  59. In order for this to work, proper GoogleService-Info.plist must be included
  60. */
  61. @try {
  62. [FIRApp configure];
  63. } @catch (NSException *exception) {
  64. NSLog(@"[LOG] Something went wrong while configuring Firebase");
  65. }
  66. if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
  67. UIUserNotificationType allNotificationTypes =(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
  68. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
  69. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  70. } else {
  71. // iOS 10 or later
  72. #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  73. // For iOS 10 display notification (sent via APNS)
  74. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  75. UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  76. [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
  77. }];
  78. // For iOS 10 data message (sent via FCM)
  79. [FIRMessaging messaging].remoteMessageDelegate = self;
  80. #endif
  81. }
  82. }
  83. NSString *dir;
  84. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  85. NSLog(@"[LOG] Start program group -----------------");
  86. NSLog(@"%@", dirGroup);
  87. NSLog(@"[LOG] Start program application -----------");
  88. NSLog(@"%@", [[CCUtility getDirectoryLocal] stringByDeletingLastPathComponent]);
  89. NSLog(@"[LOG] -------------------------------------");
  90. // create Directory local => Documents
  91. dir = [CCUtility getDirectoryLocal];
  92. if (![[NSFileManager defaultManager] fileExistsAtPath: dir] && [dir length])
  93. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  94. // create Directory audio => Library, Application Support, audio
  95. dir = [CCUtility getDirectoryAudio];
  96. if (![[NSFileManager defaultManager] fileExistsAtPath: dir] && [dir length])
  97. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  98. // create Crypto Cloud in Group => Library, Application Support, Crypto Cloud
  99. dir = [[dirGroup URLByAppendingPathComponent:appDatabase] path];
  100. if (![[NSFileManager defaultManager] fileExistsAtPath:dir])
  101. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  102. //[CCCoreData verifyVersionCoreData];
  103. [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(id)[dirGroup URLByAppendingPathComponent:[appDatabase stringByAppendingPathComponent:@"cryptocloud"]]];
  104. #ifdef DEBUG
  105. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelWarn];
  106. #else
  107. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff];
  108. #endif
  109. // Verify upgrade
  110. [self upgrade];
  111. // Set account, if no exists clear all
  112. TableAccount *recordAccount = [CCCoreData getActiveAccount];
  113. if (recordAccount == nil) {
  114. // remove all the keys Chain
  115. [CCUtility deleteAllChainStore];
  116. // remove all the App group key
  117. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  118. } else {
  119. [self settingActiveAccount:recordAccount.account activeUrl:recordAccount.url activeUser:recordAccount.user activePassword:recordAccount.password];
  120. }
  121. // Operation Queue OC Networking
  122. _netQueue = [[NSOperationQueue alloc] init];
  123. _netQueue.name = k_queue;
  124. _netQueue.maxConcurrentOperationCount = k_maxConcurrentOperation;
  125. _netQueueDownload = [[NSOperationQueue alloc] init];
  126. _netQueueDownload.name = k_download_queue;
  127. _netQueueDownload.maxConcurrentOperationCount = k_maxConcurrentOperationDownloadUpload;
  128. _netQueueDownloadWWan = [[NSOperationQueue alloc] init];
  129. _netQueueDownloadWWan.name = k_download_queuewwan;
  130. _netQueueDownloadWWan.maxConcurrentOperationCount = k_maxConcurrentOperationDownloadUpload;
  131. _netQueueUpload = [[NSOperationQueue alloc] init];
  132. _netQueueUpload.name = k_upload_queue;
  133. _netQueueUpload.maxConcurrentOperationCount = k_maxConcurrentOperationDownloadUpload;
  134. _netQueueUploadWWan = [[NSOperationQueue alloc] init];
  135. _netQueueUploadWWan.name = k_upload_queuewwan;
  136. _netQueueUploadWWan.maxConcurrentOperationCount = k_maxConcurrentOperationDownloadUpload;
  137. // Check new Asset Photos/Video in progress
  138. _automaticCheckAssetInProgress = NO;
  139. _automaticUploadInProgress = NO;
  140. // Add notification change session
  141. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionChanged:) name:k_networkingSessionNotification object:nil];
  142. // Initialization Share
  143. self.sharesID = [NSMutableDictionary new];
  144. self.sharesLink = [NSMutableDictionary new];
  145. self.sharesUserAndGroup = [NSMutableDictionary new];
  146. // Initialization Notification
  147. self.listOfNotifications = [NSMutableArray new];
  148. // Verify Session in progress and Init date task
  149. self.sessionDateLastDownloadTasks = [NSDate date];
  150. self.sessionDateLastUploadTasks = [NSDate date];
  151. // Background Fetch
  152. [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
  153. // Initialization List
  154. self.listProgressMetadata = [[NSMutableDictionary alloc] init];
  155. self.listChangeTask = [[NSMutableDictionary alloc] init];
  156. self.listMainVC = [[NSMutableDictionary alloc] init];
  157. // Player audio
  158. self.player = [LMMediaPlayerView sharedPlayerView];
  159. self.player.delegate = self;
  160. // ico Image Cache
  161. self.icoImagesCache = [[NSMutableDictionary alloc] init];
  162. // remove tmp & cache
  163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  164. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  165. for (NSString *file in tmpDirectory) {
  166. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  167. }
  168. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  169. });
  170. // setting Reachable in back
  171. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  172. self.reachability = [Reachability reachabilityForInternetConnection];
  173. self.lastReachability = [self.reachability isReachable];
  174. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
  175. [self.reachability startNotifier];
  176. });
  177. //AV Session
  178. [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
  179. //[[AVAudioSession sharedInstance] setActive:YES error:nil];
  180. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  181. // Tint Color GLOBAL WINDOW
  182. [self.window setTintColor:[NCColorBrand sharedInstance].windowTintcolor];
  183. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  184. //UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  185. UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
  186. navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  187. splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  188. [CCAspect aspectNavigationControllerBar:navigationController.navigationBar encrypted:NO online:YES hidden:NO];
  189. // Settings TabBar
  190. [self createTabBarController];
  191. // passcode
  192. [[BKPasscodeLockScreenManager sharedManager] setDelegate:self];
  193. dispatch_async(dispatch_get_main_queue(), ^{
  194. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:NO];
  195. });
  196. // Quick Actions
  197. if([[UIApplicationShortcutItem class] respondsToSelector:@selector(new)]) {
  198. [self configDynamicShortcutItems];
  199. UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
  200. if (shortcutItem)
  201. [self handleShortCutItem:shortcutItem];
  202. }
  203. // Start Timer
  204. self.timerProcess = [NSTimer scheduledTimerWithTimeInterval:k_timerProcess target:self selector:@selector(process) userInfo:nil repeats:YES];
  205. self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:k_timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
  206. self.timerUpdateApplicationIconBadgeNumber = [NSTimer scheduledTimerWithTimeInterval:k_timerUpdateApplicationIconBadgeNumber target:self selector:@selector(updateApplicationIconBadgeNumber) userInfo:nil repeats:YES];
  207. // Registration Push Notification
  208. UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
  209. UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
  210. [application registerUserNotificationSettings:notificationSettings];
  211. return YES;
  212. }
  213. //
  214. // L' applicazione si dimetterà dallo stato di attivo
  215. //
  216. - (void)applicationWillResignActive:(UIApplication *)application
  217. {
  218. [_activeMain closeAllMenu];
  219. [self updateApplicationIconBadgeNumber];
  220. }
  221. //
  222. // L' applicazione entrerà in primo piano (attivo solo dopo il background)
  223. //
  224. - (void)applicationWillEnterForeground:(UIApplication *)application
  225. {
  226. // facciamo partire il timer per il controllo delle sessioni e dei Lock
  227. [self.timerVerifySessionInProgress invalidate];
  228. self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:k_timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
  229. // refresh active Main
  230. if (_activeMain)
  231. [_activeMain reloadDatasource];
  232. // Initializations
  233. [self applicationInitialized];
  234. }
  235. //
  236. // L' applicazione è entrata nello sfondo
  237. //
  238. - (void)applicationDidEnterBackground:(UIApplication *)application
  239. {
  240. NSLog(@"[LOG] Enter in Background");
  241. [[CCQuickActions quickActionsManager] closeAll];
  242. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:YES];
  243. if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
  244. __block UIBackgroundTaskIdentifier background_task;
  245. background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
  246. //Clean up code. Tell the system that we are done.
  247. [application endBackgroundTask: background_task];
  248. background_task = UIBackgroundTaskInvalid;
  249. }];
  250. }
  251. }
  252. //
  253. // L'applicazione terminerà
  254. //
  255. - (void)applicationWillTerminate:(UIApplication *)application
  256. {
  257. [MagicalRecord cleanUp];
  258. NSLog(@"[LOG] bye bye, Crypto Cloud !");
  259. }
  260. //
  261. // Application Initialized
  262. //
  263. - (void)applicationInitialized
  264. {
  265. // Execute : now
  266. NSLog(@"[LOG] Update Folder Photo");
  267. NSString *folderCameraUpload = [CCCoreData getCameraUploadFolderNamePathActiveAccount:self.activeAccount activeUrl:self.activeUrl];
  268. if ([folderCameraUpload length] > 0)
  269. [[CCSynchronize sharedSynchronize] readFolderServerUrl:folderCameraUpload directoryID:[CCCoreData getDirectoryIDFromServerUrl:folderCameraUpload activeAccount:self.activeAccount] selector:selectorReadFolder];
  270. // Execute : after 0.5 sec.
  271. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  272. NSLog(@"[LOG] Request Server Information");
  273. if (_activeMain)
  274. [_activeMain requestServerInformation];
  275. NSLog(@"[LOG] Initialize Camera Upload");
  276. [[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:nil];
  277. NSLog(@"[LOG] Listning Favorites");
  278. [[CCSynchronize sharedSynchronize] readListingFavorites];
  279. });
  280. // Initialize Camera Upload
  281. //[[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:@{@"afterDelay": @(2)}];
  282. }
  283. #pragma --------------------------------------------------------------------------------------------
  284. #pragma mark ===== Process k_timerProcess seconds =====
  285. #pragma --------------------------------------------------------------------------------------------
  286. - (void)process
  287. {
  288. // BACKGROND & FOREGROUND
  289. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
  290. // ONLY BACKGROUND
  291. } else {
  292. // ONLY FOREFROUND
  293. [app performSelectorOnMainThread:@selector(loadAutomaticUpload) withObject:nil waitUntilDone:NO];
  294. }
  295. }
  296. #pragma --------------------------------------------------------------------------------------------
  297. #pragma mark ===== Setting Active Account =====
  298. #pragma --------------------------------------------------------------------------------------------
  299. - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activePassword:(NSString *)activePassword
  300. {
  301. self.activeAccount = activeAccount;
  302. self.activeUrl = activeUrl;
  303. self.activeUser = activeUser;
  304. self.activePassword = activePassword;
  305. self.directoryUser = [CCUtility getDirectoryActiveUser:activeUser activeUrl:activeUrl];
  306. }
  307. #pragma --------------------------------------------------------------------------------------------
  308. #pragma mark ===== Push Notification =====
  309. #pragma --------------------------------------------------------------------------------------------
  310. - (void)subscribingNextcloudServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  311. {
  312. NSLog(@"[LOG] Error Subscribing Nextcloud Server %@", message);
  313. }
  314. - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
  315. {
  316. [application registerForRemoteNotifications];
  317. }
  318. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  319. {
  320. // test
  321. if (self.activeAccount.length == 0)
  322. return;
  323. // FIREBASE registered token
  324. [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];
  325. NSString *pushToken = [[FIRInstanceID instanceID] token];
  326. // NSString *pushToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""];
  327. NSString *pushTokenHash = [[CCCrypto sharedManager] createSHA512:pushToken];
  328. NSDictionary *devicePushKey = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"DevicePushKey-Info" ofType:@"plist"]];
  329. #ifdef DEBUG
  330. NSString *devicePublicKey = [devicePushKey objectForKey:@"devicePublicKeyDevelopment"];
  331. #else
  332. NSString *devicePublicKey = [devicePushKey objectForKey:@"devicePublicKeyProduction"];
  333. #endif
  334. if ([devicePublicKey length] > 0 && [pushTokenHash length] > 0) {
  335. NSLog(@"[LOG] Firebase InstanceID push token: %@", pushToken);
  336. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  337. NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:pushToken, @"pushToken", pushTokenHash, @"pushTokenHash", devicePublicKey, @"devicePublicKey", nil];
  338. metadataNet.action = actionSubscribingNextcloudServer;
  339. metadataNet.options = options;
  340. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  341. }
  342. }
  343. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  344. {
  345. NSLog(@"[LOG] Error register remote notification %@", error);
  346. }
  347. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  348. UIApplicationState state = [application applicationState];
  349. if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
  350. NSLog(@"[LOG] Receive Notification on Inactive or Background state");
  351. } else {
  352. NSLog(@"[LOG] Receive Notification on Active state");
  353. }
  354. // If you are receiving a notification message while your app is in the background,
  355. // this callback will not be fired till the user taps on the notification launching the application.
  356. // TODO: Handle data of notification
  357. // Print message ID.
  358. //if (userInfo[kGCMMessageIDKey]) {
  359. // NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  360. //}
  361. // Print full message.
  362. NSLog(@"[LOG] %@", userInfo);
  363. }
  364. - (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  365. {
  366. UIApplicationState state = [application applicationState];
  367. // Print message ID.
  368. //if (userInfo[kGCMMessageIDKey]) {
  369. // NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  370. //}
  371. // Print full message.
  372. NSLog(@"[LOG] %@", userInfo);
  373. if (state == UIApplicationStateBackground || (state == UIApplicationStateInactive)) {
  374. } else if (state == UIApplicationStateInactive) {
  375. // user tapped notification
  376. completionHandler(UIBackgroundFetchResultNewData);
  377. } else {
  378. // app is active
  379. completionHandler(UIBackgroundFetchResultNoData);
  380. }
  381. }
  382. #pragma FIREBASE
  383. - (void)tokenRefreshNotification:(NSNotification *)notification {
  384. // Note that this callback will be fired everytime a new token is generated, including the first
  385. // time. So if you need to retrieve the token as soon as it is available this is where that
  386. // should be done.
  387. NSString *refreshedToken = [[FIRInstanceID instanceID] token];
  388. NSLog(@"[LOG] InstanceID token: %@", refreshedToken);
  389. // Connect to FCM since connection may have failed when attempted before having a token.
  390. [self connectToFcm];
  391. // TODO: If necessary send token to application server.
  392. }
  393. - (void)connectToFcm {
  394. // Won't connect since there is no token
  395. if (![[FIRInstanceID instanceID] token]) {
  396. return;
  397. }
  398. // Disconnect previous FCM connection if it exists.
  399. [[FIRMessaging messaging] disconnect];
  400. [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {
  401. if (error != nil) {
  402. NSLog(@"[LOG] Unable to connect to FCM. %@", error);
  403. } else {
  404. NSLog(@"[LOG] Connected to FCM.");
  405. }
  406. }];
  407. }
  408. #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  409. // Receive data message on iOS 10 devices while app is in the foreground.
  410. - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
  411. // Print full message
  412. NSLog(@"[LOG] %@", remoteMessage.appData);
  413. }
  414. #endif
  415. #pragma --------------------------------------------------------------------------------------------
  416. #pragma mark ===== Quick Actions - ShotcutItem =====
  417. #pragma --------------------------------------------------------------------------------------------
  418. - (void)configDynamicShortcutItems
  419. {
  420. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  421. UIApplicationShortcutIcon *shortcutPhotosIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionPhotos];
  422. UIApplicationShortcutIcon *shortcutUploadIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionUpload];
  423. UIApplicationShortcutIcon *shortcutUploadEncryptedIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionUploadEncrypted];
  424. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:NSLocalizedString(@"_photo_camera_", nil) localizedSubtitle:nil icon:shortcutPhotosIcon userInfo:nil];
  425. UIApplicationShortcutItem *shortcutUpload = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.upload", bundleId] localizedTitle:NSLocalizedString(@"_upload_file_", nil) localizedSubtitle:nil icon:shortcutUploadIcon userInfo:nil];
  426. UIApplicationShortcutItem *shortcutUploadEncrypted = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.uploadEncrypted", bundleId] localizedTitle:NSLocalizedString(@"_upload_encrypted_file_", nil) localizedSubtitle:nil icon:shortcutUploadEncryptedIcon userInfo:nil];
  427. if (app.isCryptoCloudMode) {
  428. // add the array to our app
  429. [UIApplication sharedApplication].shortcutItems = @[shortcutUploadEncrypted, shortcutUpload, shortcutPhotos];
  430. } else {
  431. // add the array to our app
  432. [UIApplication sharedApplication].shortcutItems = @[shortcutUpload, shortcutPhotos];
  433. }
  434. }
  435. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  436. {
  437. BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];
  438. completionHandler(handledShortCutItem);
  439. }
  440. - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem
  441. {
  442. BOOL handled = NO;
  443. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  444. NSString *shortcutPhotos = [NSString stringWithFormat:@"%@.photos", bundleId];
  445. NSString *shortcutUpload = [NSString stringWithFormat:@"%@.upload", bundleId];
  446. NSString *shortcutUploadEncrypted = [NSString stringWithFormat:@"%@.uploadEncrypted", bundleId];
  447. if ([shortcutItem.type isEqualToString:shortcutUpload] && self.activeAccount) {
  448. dispatch_async(dispatch_get_main_queue(), ^{
  449. if (_activeMain) {
  450. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  451. if (splitViewController.isCollapsed) {
  452. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  453. for (UINavigationController *nvc in tbc.viewControllers) {
  454. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  455. [nvc popToRootViewControllerAnimated:NO];
  456. }
  457. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  458. } else {
  459. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  460. [nvcDetail popToRootViewControllerAnimated:NO];
  461. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  462. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  463. }
  464. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  465. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  466. [[CCQuickActions quickActionsManager] startQuickActionsEncrypted:NO viewController:_activeMain];
  467. });
  468. }
  469. });
  470. handled = YES;
  471. }
  472. else if ([shortcutItem.type isEqualToString:shortcutUploadEncrypted] && self.activeAccount) {
  473. dispatch_async(dispatch_get_main_queue(), ^{
  474. if (_activeMain) {
  475. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  476. if (splitViewController.isCollapsed) {
  477. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  478. for (UINavigationController *nvc in tbc.viewControllers) {
  479. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  480. [nvc popToRootViewControllerAnimated:NO];
  481. }
  482. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  483. } else {
  484. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  485. [nvcDetail popToRootViewControllerAnimated:NO];
  486. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  487. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  488. }
  489. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  490. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  491. [[CCQuickActions quickActionsManager] startQuickActionsEncrypted:YES viewController:_activeMain];
  492. });
  493. }
  494. });
  495. handled = YES;
  496. }
  497. else if ([shortcutItem.type isEqualToString:shortcutPhotos] && self.activeAccount) {
  498. dispatch_async(dispatch_get_main_queue(), ^{
  499. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  500. if (splitViewController.isCollapsed) {
  501. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  502. for (UINavigationController *nvc in tbc.viewControllers) {
  503. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  504. [nvc popToRootViewControllerAnimated:NO];
  505. }
  506. [tbc setSelectedIndex: k_tabBarApplicationIndexPhotos];
  507. } else {
  508. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  509. [nvcDetail popToRootViewControllerAnimated:NO];
  510. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  511. [tbc setSelectedIndex: k_tabBarApplicationIndexPhotos];
  512. }
  513. });
  514. handled = YES;
  515. }
  516. return handled;
  517. }
  518. #pragma --------------------------------------------------------------------------------------------
  519. #pragma mark ===== StatusBar & ApplicationIconBadgeNumber =====
  520. #pragma --------------------------------------------------------------------------------------------
  521. - (void)messageNotification:(NSString *)title description:(NSString *)description visible:(BOOL)visible delay:(NSTimeInterval)delay type:(TWMessageBarMessageType)type
  522. {
  523. title = [NSString stringWithFormat:@"%@\n",[CCUtility localizableBrand:title table:nil]];
  524. dispatch_async(dispatch_get_main_queue(), ^{
  525. if (visible) {
  526. [TWMessageBarManager sharedInstance].styleSheet = self;
  527. [[TWMessageBarManager sharedInstance] showMessageWithTitle:title description:[CCUtility localizableBrand:description table:nil] type:type duration:delay];
  528. } else {
  529. [[TWMessageBarManager sharedInstance] hideAllAnimated:YES];
  530. }
  531. });
  532. }
  533. - (UIColor *)backgroundColorForMessageType:(TWMessageBarMessageType)type
  534. {
  535. UIColor *backgroundColor = nil;
  536. switch (type)
  537. {
  538. case TWMessageBarMessageTypeError:
  539. backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.90];
  540. break;
  541. case TWMessageBarMessageTypeSuccess:
  542. backgroundColor = [UIColor colorWithRed:0.588 green:0.797 blue:0.000 alpha:0.90];
  543. break;
  544. case TWMessageBarMessageTypeInfo:
  545. backgroundColor = [NCColorBrand sharedInstance].messageInfoBackground;
  546. break;
  547. default:
  548. break;
  549. }
  550. return backgroundColor;
  551. }
  552. - (UIColor *)strokeColorForMessageType:(TWMessageBarMessageType)type
  553. {
  554. UIColor *strokeColor = nil;
  555. switch (type)
  556. {
  557. case TWMessageBarMessageTypeError:
  558. strokeColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
  559. break;
  560. case TWMessageBarMessageTypeSuccess:
  561. strokeColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
  562. break;
  563. case TWMessageBarMessageTypeInfo:
  564. strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
  565. break;
  566. default:
  567. break;
  568. }
  569. return strokeColor;
  570. }
  571. - (UIImage *)iconImageForMessageType:(TWMessageBarMessageType)type
  572. {
  573. UIImage *iconImage = nil;
  574. switch (type)
  575. {
  576. case TWMessageBarMessageTypeError:
  577. iconImage = [UIImage imageNamed:@"icon-error.png"];
  578. break;
  579. case TWMessageBarMessageTypeSuccess:
  580. iconImage = [UIImage imageNamed:@"icon-success.png"];
  581. break;
  582. case TWMessageBarMessageTypeInfo:
  583. iconImage = [UIImage imageNamed:@"icon-info.png"];
  584. break;
  585. default:
  586. break;
  587. }
  588. return iconImage;
  589. }
  590. #pragma --------------------------------------------------------------------------------------------
  591. #pragma mark ===== TabBarController =====
  592. #pragma --------------------------------------------------------------------------------------------
  593. - (void)createTabBarController
  594. {
  595. UITabBarItem *item;
  596. NSLayoutConstraint *constraint;
  597. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  598. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  599. [CCAspect aspectTabBar:tabBarController.tabBar hidden:NO];
  600. // File
  601. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
  602. [item setTitle:NSLocalizedString(@"_home_", nil)];
  603. item.image = [UIImage imageNamed:image_tabBarFiles];
  604. item.selectedImage = [UIImage imageNamed:image_tabBarFiles];
  605. // Favorites
  606. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  607. [item setTitle:NSLocalizedString(@"_favorites_", nil)];
  608. item.image = [UIImage imageNamed:image_tabBarFavorite];
  609. item.selectedImage = [UIImage imageNamed:image_tabBarFavorite];
  610. // Hide (PLUS)
  611. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexHide];
  612. item.title = nil;
  613. item.image = nil;
  614. item.enabled = false;
  615. // Photos
  616. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexPhotos];
  617. [item setTitle:NSLocalizedString(@"_photo_camera_", nil)];
  618. item.image = [UIImage imageNamed:image_tabBarPhotos];
  619. item.selectedImage = [UIImage imageNamed:image_tabBarPhotos];
  620. // More
  621. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexMore];
  622. [item setTitle:NSLocalizedString(@"_more_", nil)];
  623. item.image = [UIImage imageNamed:image_tabBarMore];
  624. item.selectedImage = [UIImage imageNamed:image_tabBarMore];
  625. // Plus Button
  626. UIImage *buttonImage = [UIImage imageNamed:image_tabBarPlus];
  627. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  628. button.tag = 99;
  629. button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
  630. [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
  631. [button setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  632. [button addTarget:self action:@selector(handleTouchTabbarCenter:) forControlEvents:UIControlEventTouchUpInside];
  633. [button setTranslatesAutoresizingMaskIntoConstraints:NO];
  634. [tabBarController.view addSubview:button];
  635. constraint =[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:tabBarController.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
  636. [tabBarController.view addConstraint:constraint];
  637. constraint =[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:tabBarController.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5];
  638. [tabBarController.view addConstraint:constraint];
  639. }
  640. - (void)plusButtonVisibile:(BOOL)visible
  641. {
  642. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  643. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  644. UIButton *buttonPlus = [tabBarController.view viewWithTag:99];
  645. if (buttonPlus) {
  646. if (visible) {
  647. buttonPlus.hidden = false;
  648. } else {
  649. buttonPlus.hidden = true;
  650. }
  651. }
  652. }
  653. - (void)handleTouchTabbarCenter:(id)sender
  654. {
  655. CreateMenuAdd *menuAdd = [[CreateMenuAdd alloc] init];
  656. if ([CCUtility getCreateMenuEncrypted])
  657. [menuAdd createMenuEncryptedWithView:self.window.rootViewController.view];
  658. else
  659. [menuAdd createMenuPlainWithView:self.window.rootViewController.view];
  660. }
  661. - (void)updateApplicationIconBadgeNumber
  662. {
  663. // Core Data
  664. _queueNunDownload = [[CCCoreData getTableMetadataDownloadAccount:self.activeAccount] count];
  665. _queueNumDownloadWWan = [[CCCoreData getTableMetadataDownloadWWanAccount:self.activeAccount] count];
  666. _queueNumUpload = [[CCCoreData getTableMetadataUploadAccount:self.activeAccount] count];
  667. _queueNumUploadWWan = [[CCCoreData getTableMetadataUploadWWanAccount:self.activeAccount] count];
  668. // netQueueDownload
  669. for (NSOperation *operation in [app.netQueueDownload operations])
  670. if (((OCnetworking *)operation).isExecuting == NO) _queueNunDownload++;
  671. // netQueueDownloadWWan
  672. for (NSOperation *operation in [app.netQueueDownloadWWan operations])
  673. if (((OCnetworking *)operation).isExecuting == NO) _queueNumDownloadWWan++;
  674. // netQueueUpload
  675. for (NSOperation *operation in [app.netQueueUpload operations])
  676. if (((OCnetworking *)operation).isExecuting == NO) _queueNumUpload++;
  677. // netQueueUploadWWan
  678. for (NSOperation *operation in [app.netQueueUploadWWan operations])
  679. if (((OCnetworking *)operation).isExecuting == NO) _queueNumUploadWWan++;
  680. // Total
  681. NSUInteger total = _queueNunDownload + _queueNumDownloadWWan + _queueNumUpload + _queueNumUploadWWan + [CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:nil];
  682. [UIApplication sharedApplication].applicationIconBadgeNumber = total;
  683. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  684. if ([[splitViewController.viewControllers firstObject] isKindOfClass:[UITabBarController class]]) {
  685. UITabBarController *tbc = [splitViewController.viewControllers firstObject];
  686. UITabBarItem *tbItem = [tbc.tabBar.items objectAtIndex:0];
  687. if (total > 0)
  688. [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
  689. else
  690. [tbItem setBadgeValue:nil];
  691. }
  692. }
  693. #pragma --------------------------------------------------------------------------------------------
  694. #pragma mark ===== Media Player Control =====
  695. #pragma --------------------------------------------------------------------------------------------
  696. - (void)remoteControlReceivedWithEvent:(UIEvent *)event
  697. {
  698. switch (event.subtype) {
  699. case UIEventSubtypeRemoteControlPlay:
  700. if (self.player.mediaPlayer) {
  701. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  702. if (self.player.mediaPlayer.nowPlayingItem.title)
  703. [songInfo setObject:self.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  704. if (self.player.mediaPlayer.nowPlayingItem.artist)
  705. [songInfo setObject:self.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  706. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  707. [self.player.mediaPlayer play];
  708. }
  709. break;
  710. case UIEventSubtypeRemoteControlPause:
  711. if (self.player.mediaPlayer) {
  712. [self.player.mediaPlayer pause];
  713. }
  714. break;
  715. case UIEventSubtypeRemoteControlNextTrack:
  716. // handle it break;
  717. case UIEventSubtypeRemoteControlPreviousTrack:
  718. // handle it break;
  719. default:
  720. break;
  721. }
  722. }
  723. - (BOOL)mediaPlayerViewWillStartPlaying:(LMMediaPlayerView *)playerView media:(LMMediaItem *)media
  724. {
  725. return YES;
  726. }
  727. #pragma --------------------------------------------------------------------------------------------
  728. #pragma mark ===== Manager Passcode =====
  729. #pragma --------------------------------------------------------------------------------------------
  730. - (BOOL)lockScreenManagerShouldShowLockScreen:(BKPasscodeLockScreenManager *)aManager
  731. {
  732. // ServerUrl active
  733. NSString *serverUrl = self.activeMain.serverUrl;
  734. // fermiamo la data della sessione
  735. self.sessionePasscodeLock = nil;
  736. // se il block code è a zero esci con NON attivare la richiesta password
  737. if ([[CCUtility getBlockCode] length] == 0) return NO;
  738. // se non c'è attivo un account esci con NON attivare la richiesta password
  739. if ([self.activeAccount length] == 0) return NO;
  740. // se non è attivo il OnlyLockDir esci con NON attivare la richiesta password
  741. if ([CCUtility getOnlyLockDir] && ![CCCoreData isBlockZone:serverUrl activeAccount:self.activeAccount]) return NO;
  742. return YES;
  743. }
  744. - (UIViewController *)lockScreenManagerPasscodeViewController:(BKPasscodeLockScreenManager *)aManager
  745. {
  746. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  747. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  748. viewController.delegate = self;
  749. viewController.title = k_brand;
  750. viewController.fromType = CCBKPasscodeFromLockScreen;
  751. viewController.inputViewTitlePassword = YES;
  752. if ([CCUtility getSimplyBlockCode]) {
  753. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  754. viewController.passcodeInputView.maximumLength = 6;
  755. } else {
  756. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  757. viewController.passcodeInputView.maximumLength = 64;
  758. }
  759. viewController.touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName: k_serviceShareKeyChain];
  760. viewController.touchIDManager.promptText = [CCUtility localizableBrand:@"_scan_fingerprint_" table:nil];
  761. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  762. return navigationController;
  763. }
  764. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  765. {
  766. [aViewController dismissViewControllerAnimated:YES completion:nil];
  767. // is a lock screen
  768. if (aViewController.fromType == CCBKPasscodeFromLockScreen) {
  769. [aViewController dismissViewControllerAnimated:YES completion:nil];
  770. // start session Passcode Lock
  771. NSString *serverUrl = self.activeMain.serverUrl;
  772. if ([CCCoreData isBlockZone:serverUrl activeAccount:self.activeAccount])
  773. self.sessionePasscodeLock = [NSDate date];
  774. }
  775. }
  776. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  777. {
  778. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromInit) {
  779. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  780. //self.lockUntilDate = nil;
  781. //self.failedAttempts = 0;
  782. aResultHandler(YES);
  783. } else aResultHandler(NO);
  784. } else aResultHandler(YES);
  785. }
  786. #pragma --------------------------------------------------------------------------------------------
  787. #pragma mark ===== reachabilityChanged =====
  788. #pragma --------------------------------------------------------------------------------------------
  789. -(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
  790. {
  791. if ([self.reachability isReachable]) {
  792. if (self.lastReachability == NO) {
  793. [self messageNotification:@"_network_available_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  794. if (_activeMain)
  795. [_activeMain performSelector:@selector(requestServerInformation) withObject:nil afterDelay:3];
  796. }
  797. NSLog(@"[LOG] Reachability Changed: Reachable");
  798. self.lastReachability = YES;
  799. } else {
  800. if (self.lastReachability == YES) {
  801. [self messageNotification:@"_network_not_available_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  802. }
  803. NSLog(@"[LOG] Reachability Changed: NOT Reachable");
  804. self.lastReachability = NO;
  805. }
  806. if ([self.reachability isReachableViaWiFi]) NSLog(@"[LOG] Reachability Changed: WiFi");
  807. if ([self.reachability isReachableViaWWAN]) NSLog(@"[LOG] Reachability Changed: WWAn");
  808. [[NSNotificationCenter defaultCenter] postNotificationName:@"setTitleMain" object:nil];
  809. }
  810. #pragma --------------------------------------------------------------------------------------------
  811. #pragma mark ===== Fetch =====
  812. #pragma --------------------------------------------------------------------------------------------
  813. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  814. {
  815. NSLog(@"[LOG] Start Fetch");
  816. // Verify new photo
  817. [[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:nil];
  818. // after 20 sec verify Re
  819. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  820. [[CCNetworking sharedNetworking] automaticDownloadInError];
  821. [[CCNetworking sharedNetworking] automaticUploadInError];
  822. NSLog(@"[LOG] End Fetch 20 sec.");
  823. });
  824. // after 25 sec
  825. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  826. NSArray *records = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session != NULL) AND (session != '')", self.activeAccount] context:nil];
  827. if ([records count] > 0) {
  828. completionHandler(UIBackgroundFetchResultNewData);
  829. } else {
  830. completionHandler(UIBackgroundFetchResultNoData);
  831. }
  832. NSLog(@"[LOG] End Fetch 25 sec.");
  833. });
  834. }
  835. #pragma --------------------------------------------------------------------------------------------
  836. #pragma mark ===== Operation Networking & Session =====
  837. #pragma --------------------------------------------------------------------------------------------
  838. //
  839. // Method called by the system when all the background task has end
  840. //
  841. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
  842. {
  843. NSLog(@"[LOG] Start completition handler from background - identifier : %@", identifier);
  844. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  845. [[CCNetworking sharedNetworking] automaticDownloadInError];
  846. [[CCNetworking sharedNetworking] automaticUploadInError];
  847. self.backgroundSessionCompletionHandler = completionHandler;
  848. void (^completionHandler)() = self.backgroundSessionCompletionHandler;
  849. self.backgroundSessionCompletionHandler = nil;
  850. completionHandler();
  851. NSLog(@"[LOG] End 25 sec. completition handler - identifier : %@", identifier);
  852. });
  853. }
  854. - (void)cancelAllOperations
  855. {
  856. [_netQueue cancelAllOperations];
  857. [_netQueueDownload cancelAllOperations];
  858. [_netQueueDownloadWWan cancelAllOperations];
  859. [_netQueueUpload cancelAllOperations];
  860. [_netQueueUploadWWan cancelAllOperations];
  861. }
  862. - (void)addNetworkingOperationQueue:(NSOperationQueue *)netQueue delegate:(id)delegate metadataNet:(CCMetadataNet *)metadataNet
  863. {
  864. id operation;
  865. operation = [[OCnetworking alloc] initWithDelegate:delegate metadataNet:metadataNet withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl isCryptoCloudMode:_isCryptoCloudMode];
  866. [operation setQueuePriority:metadataNet.priority];
  867. [netQueue addOperation:operation];
  868. }
  869. - (NSMutableArray *)verifyExistsInQueuesDownloadSelector:(NSString *)selector
  870. {
  871. NSMutableArray *metadatasNet = [[NSMutableArray alloc] init];
  872. for (OCnetworking *operation in [self.netQueueDownload operations])
  873. if ([operation.metadataNet.selector isEqualToString:selector])
  874. [metadatasNet addObject:[operation.metadataNet copy]];
  875. for (OCnetworking *operation in [self.netQueueDownloadWWan operations])
  876. if ([operation.metadataNet.selector isEqualToString:selector])
  877. [metadatasNet addObject:[operation.metadataNet copy]];
  878. return metadatasNet;
  879. }
  880. - (void)loadAutomaticUpload
  881. {
  882. CCMetadataNet *metadataNet;
  883. // Is loading new Asset or this ?
  884. if (_automaticCheckAssetInProgress || _automaticUploadInProgress)
  885. return;
  886. // START Automatic Upload in progress
  887. _automaticUploadInProgress = YES;
  888. NSArray *uploadInQueue = [CCCoreData getTableMetadataUploadAccount:app.activeAccount];
  889. NSArray *recordAutomaticUploadInLock = [CCCoreData getAllLockTableAutomaticUploadForAccount:_activeAccount];
  890. for (TableAutomaticUpload *tableAutomaticUpload in recordAutomaticUploadInLock) {
  891. BOOL recordFound = NO;
  892. for (CCMetadataNet *metadataNet in uploadInQueue) {
  893. if (metadataNet.assetLocalIdentifier == tableAutomaticUpload.assetLocalIdentifier)
  894. recordFound = YES;
  895. }
  896. if (!recordFound)
  897. [CCCoreData unlockTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:tableAutomaticUpload.assetLocalIdentifier];
  898. }
  899. // ------------------------- <selectorUploadAutomatic> -------------------------
  900. metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomatic];
  901. while (metadataNet) {
  902. PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadataNet.assetLocalIdentifier] options:nil];
  903. if (result.count) {
  904. [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet.assetLocalIdentifier fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl cryptated:metadataNet.cryptated session:metadataNet.session taskStatus:metadataNet.taskStatus selector:metadataNet.selector selectorPost:metadataNet.selectorPost errorCode:metadataNet.errorCode delegate:app.activeMain];
  905. } else {
  906. [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutomatic note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
  907. [CCCoreData deleteTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:metadataNet.assetLocalIdentifier];
  908. }
  909. metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomatic];
  910. }
  911. // ------------------------- <selectorUploadAutomaticAll> -------------------------
  912. // Verify num error MAX 10 after STOP
  913. NSUInteger errorCount = [TableMetadata MR_countOfEntitiesWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier == %i) OR (sessionTaskIdentifierPlist == %i))", app.activeAccount, selectorUploadAutomaticAll,k_taskIdentifierError, k_taskIdentifierError]];
  914. if (errorCount >= 10) {
  915. [app messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  916. // STOP Im progress
  917. _automaticUploadInProgress = NO;
  918. return;
  919. }
  920. NSUInteger count = [TableMetadata MR_countOfEntitiesWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier > 0) OR (sessionTaskIdentifierPlist > 0))", app.activeAccount, selectorUploadAutomaticAll]];
  921. if (count >= k_maxConcurrentOperationDownloadUpload) {
  922. // STOP Im progress
  923. _automaticUploadInProgress = NO;
  924. return;
  925. }
  926. metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomaticAll];
  927. if (metadataNet) {
  928. PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadataNet.assetLocalIdentifier] options:nil];
  929. if (result.count) {
  930. [[CCNetworking sharedNetworking] uploadFileFromAssetLocalIdentifier:metadataNet.assetLocalIdentifier fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl cryptated:metadataNet.cryptated session:metadataNet.session taskStatus:metadataNet.taskStatus selector:metadataNet.selector selectorPost:metadataNet.selectorPost errorCode:metadataNet.errorCode delegate:app.activeMain];
  931. } else {
  932. [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutomatic note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
  933. [CCCoreData deleteTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:metadataNet.assetLocalIdentifier];
  934. }
  935. }
  936. // STOP Im progress
  937. _automaticUploadInProgress = NO;
  938. }
  939. - (void)verifyDownloadUploadInProgress
  940. {
  941. BOOL callVerifyDownload = NO;
  942. BOOL callVerifyUpload = NO;
  943. if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
  944. NSLog(@"[LOG] Verify Download/Upload in progress now : %@ - Download %@ - Upload %@", [NSDate date], [self.sessionDateLastDownloadTasks dateByAddingTimeInterval:k_timerVerifySession], [self.sessionDateLastUploadTasks dateByAddingTimeInterval:k_timerVerifySession]);
  945. if ([[NSDate date] compare:[self.sessionDateLastDownloadTasks dateByAddingTimeInterval:k_timerVerifySession]] == NSOrderedDescending) {
  946. callVerifyDownload = YES;
  947. [[CCNetworking sharedNetworking] verifyDownloadInProgress];
  948. }
  949. if ([[NSDate date] compare:[self.sessionDateLastUploadTasks dateByAddingTimeInterval:k_timerVerifySession]] == NSOrderedDescending) {
  950. callVerifyUpload = YES;
  951. [[CCNetworking sharedNetworking] verifyUploadInProgress];
  952. }
  953. if (callVerifyDownload && callVerifyUpload) {
  954. NSLog(@"[LOG] Stop timer verify session");
  955. [self.timerVerifySessionInProgress invalidate];
  956. }
  957. }
  958. }
  959. // Notification change session
  960. - (void)sessionChanged:(NSNotification *)notification
  961. {
  962. NSURLSession *session;
  963. CCMetadata *metadata;
  964. NSURLSessionTask *task;
  965. for (id object in notification.object) {
  966. if ([object isKindOfClass:[NSURLSession class]])
  967. session = object;
  968. if ([object isKindOfClass:[CCMetadata class]])
  969. metadata = object;
  970. if ([object isKindOfClass:[NSURLSessionTask class]])
  971. task = object;
  972. }
  973. /*
  974. Task
  975. */
  976. if ([task isKindOfClass:[NSURLSessionDownloadTask class]])
  977. app.sessionDateLastDownloadTasks = [NSDate date];
  978. if ([task isKindOfClass:[NSURLSessionUploadTask class]])
  979. app.sessionDateLastUploadTasks = [NSDate date];
  980. if (metadata && [_listChangeTask objectForKey:metadata.fileID])
  981. dispatch_async(dispatch_get_main_queue(), ^{
  982. [self changeTask:metadata];
  983. });
  984. /*
  985. Session
  986. */
  987. if (session) {
  988. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  989. unsigned long numDownload = [downloadTasks count];
  990. unsigned long numUpload = [uploadTasks count];
  991. NSLog(@"[LOG] Num Download in queue %lu, num upload in queue %lu", numDownload, numUpload);
  992. }];
  993. }
  994. }
  995. - (void)changeTask:(CCMetadata *)metadata
  996. {
  997. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  998. if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"stopUpload"]) {
  999. // sessionTaskIdentifier on Stop
  1000. [CCCoreData setMetadataSession:nil sessionError:@"" sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:k_taskIdentifierStop sessionTaskIdentifierPlist:k_taskIdentifierDone predicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, self.activeAccount] context:nil];
  1001. }
  1002. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"reloadUpload"]) {
  1003. // V 1.8 if upload_session_wwan change in upload_session
  1004. if ([metadata.session isEqualToString:k_upload_session_wwan])
  1005. metadata.session = k_upload_session;
  1006. [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:k_taskStatusResume];
  1007. }
  1008. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"reloadDownload"]) {
  1009. BOOL downloadData = NO, downloadPlist = NO;
  1010. if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) downloadData = YES;
  1011. if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) downloadPlist = YES;
  1012. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1013. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:downloadData downloadPlist:downloadPlist selector:metadata.sessionSelector selectorPost:metadata.sessionSelectorPost session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  1014. });
  1015. }
  1016. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"cancelUpload"]) {
  1017. // remove the file
  1018. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, app.activeAccount]];
  1019. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] error:nil];
  1020. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID] error:nil];
  1021. }
  1022. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"cancelDownload"]) {
  1023. [CCCoreData setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionSelectorPost:@"" sessionTaskIdentifier:k_taskIdentifierDone sessionTaskIdentifierPlist:k_taskIdentifierDone predicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, self.activeAccount] context:nil];
  1024. }
  1025. // remove ChangeTask (fileID) from the list
  1026. [_listChangeTask removeObjectForKey:metadata.fileID];
  1027. // delete progress
  1028. [_listProgressMetadata removeObjectForKey:metadata.fileID];
  1029. // Progress Task
  1030. NSDictionary* userInfo = @{@"fileID": (metadata.fileID), @"serverUrl": (serverUrl), @"cryptated": ([NSNumber numberWithBool:NO]), @"progress": ([NSNumber numberWithFloat:0.0])};
  1031. [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationProgressTask" object:nil userInfo:userInfo];
  1032. // Refresh
  1033. if (_activeMain && [_listChangeTask count] == 0) {
  1034. [_activeMain reloadDatasource:[CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account] fileID:nil selector:nil];
  1035. }
  1036. }
  1037. - (BOOL)createFolderSubFolderAutomaticUploadFolderPhotos:(NSString *)folderPhotos useSubFolder:(BOOL)useSubFolder assets:(NSArray *)assets selector:(NSString *)selector
  1038. {
  1039. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl isCryptoCloudMode:NO];
  1040. if(![ocNetworking automaticCreateFolderSync:folderPhotos]) {
  1041. // Activity
  1042. [CCCoreData addActivityClient:folderPhotos fileID:@"" action:k_activityDebugActionAutomaticUpload selector:selector note:NSLocalizedStringFromTable(@"_not_possible_create_folder_", @"Error", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault account:_activeAccount activeUrl:_activeUrl];
  1043. return false;
  1044. }
  1045. // Create if request the subfolders
  1046. if (useSubFolder) {
  1047. for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
  1048. if(![ocNetworking automaticCreateFolderSync:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
  1049. // Activity
  1050. [CCCoreData addActivityClient:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder] fileID:@"" action:k_activityDebugActionAutomaticUpload selector:selector note:NSLocalizedString(@"_error_createsubfolders_upload_",nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault account:_activeAccount activeUrl:_activeUrl];
  1051. return false;
  1052. }
  1053. }
  1054. }
  1055. return true;
  1056. }
  1057. #pragma --------------------------------------------------------------------------------------------
  1058. #pragma mark ===== Open CCUploadFromOtherUpp =====
  1059. #pragma --------------------------------------------------------------------------------------------
  1060. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  1061. {
  1062. return YES;
  1063. }
  1064. // Method called from iOS system to send a file from other app.
  1065. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  1066. {
  1067. NSLog(@"[LOG] URL from %@ application", sourceApplication);
  1068. NSLog(@"[LOG] the path is: %@", url.path);
  1069. NSArray *splitedUrl = [url.path componentsSeparatedByString:@"/"];
  1070. self.fileNameUpload = [NSString stringWithFormat:@"%@",[splitedUrl objectAtIndex:([splitedUrl count]-1)]];
  1071. if (self.activeAccount) {
  1072. [[NSFileManager defaultManager]moveItemAtPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] stringByAppendingPathComponent:self.fileNameUpload] toPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, self.fileNameUpload] error:nil];
  1073. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  1074. UINavigationController *splitNavigationController = [splitViewController.viewControllers firstObject];
  1075. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
  1076. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1077. [splitNavigationController presentViewController:navigationController animated:YES completion:nil];
  1078. });
  1079. }
  1080. // remove from InBox
  1081. [[NSFileManager defaultManager] removeItemAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] error:nil];
  1082. return YES;
  1083. }
  1084. #pragma --------------------------------------------------------------------------------------------
  1085. #pragma mark ===== UPGRADE =====
  1086. #pragma --------------------------------------------------------------------------------------------
  1087. - (void)upgrade
  1088. {
  1089. #ifdef DEBUG
  1090. // [CCCoreData flushTableGPS];
  1091. // [CCCoreData setGeoInformationLocalNull];
  1092. #endif
  1093. NSString *actualVersion = [CCUtility getVersionCryptoCloud];
  1094. /* ---------------------- UPGRADE VERSION ----------------------- */
  1095. if (([actualVersion compare:@"2.13" options:NSNumericSearch] == NSOrderedAscending)) {
  1096. [CCCoreData flushTableDirectoryAccount:nil];
  1097. [CCCoreData flushTableLocalFileAccount:nil];
  1098. [CCCoreData flushTableMetadataAccount:nil];
  1099. }
  1100. if (([actualVersion compare:@"2.15" options:NSNumericSearch] == NSOrderedAscending)) {
  1101. [CCCoreData flushTableGPS];
  1102. [CCCoreData setGeoInformationLocalNull];
  1103. }
  1104. if (([actualVersion compare:@"2.17" options:NSNumericSearch] == NSOrderedAscending)) {
  1105. [CCCoreData clearAllDateReadDirectory];
  1106. [CCCoreData flushTableMetadataAccount:nil];
  1107. }
  1108. if (([actualVersion compare:@"2.17.1" options:NSNumericSearch] == NSOrderedAscending)) {
  1109. }
  1110. }
  1111. @end