AppDelegate.m 64 KB

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