AppDelegate.m 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  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 "OCFrameworkConstants.h"
  26. #import "AFURLSessionManager.h"
  27. #import "JBroken.h"
  28. #import "CCNetworking.h"
  29. #import "CCCoreData.h"
  30. #import "CCCrypto.h"
  31. #import "CCFavorite.h"
  32. #import "CCManageAsset.h"
  33. #import "CCGraphics.h"
  34. #import "CCPhotosCameraUpload.h"
  35. #import "CCSynchronization.h"
  36. #import "CCMain.h"
  37. #import "CCDetail.h"
  38. #import "Nextcloud-Swift.h"
  39. @interface AppDelegate ()
  40. {
  41. }
  42. @end
  43. @implementation AppDelegate
  44. + (void)initialize
  45. {
  46. [iRate sharedInstance].daysUntilPrompt = 10;
  47. [iRate sharedInstance].usesUntilPrompt = 10;
  48. [iRate sharedInstance].promptForNewVersionIfUserRated = true;
  49. //enable preview mode
  50. //[iRate sharedInstance].previewMode = YES;
  51. }
  52. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  53. {
  54. NSString *dir;
  55. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:capabilitiesGroups];
  56. NSLog(@"[LOG] Start program group %@", dirGroup);
  57. // create Directory local => Documents
  58. dir = [CCUtility getDirectoryLocal];
  59. if (![[NSFileManager defaultManager] fileExistsAtPath: dir] && [dir length])
  60. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  61. // create Directory audio => Library, Application Support, audio
  62. dir = [CCUtility getDirectoryAudio];
  63. if (![[NSFileManager defaultManager] fileExistsAtPath: dir] && [dir length])
  64. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  65. // create Crypto Cloud in Group => Library, Application Support, Crypto Cloud
  66. dir = [[dirGroup URLByAppendingPathComponent:appDatabase] path];
  67. if (![[NSFileManager defaultManager] fileExistsAtPath:dir])
  68. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  69. //[CCCoreData verifyVersionCoreData];
  70. [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(id)[dirGroup URLByAppendingPathComponent:[appDatabase stringByAppendingPathComponent:@"cryptocloud"]]];
  71. #ifdef DEBUG
  72. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelWarn];
  73. #else
  74. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff];
  75. #endif
  76. // Verify upgrade
  77. [self upgrade];
  78. // Set account, if no exists clear all
  79. TableAccount *recordAccount = [CCCoreData getActiveAccount];
  80. if (recordAccount == nil) {
  81. // remove all the keys Chain
  82. [CCUtility deleteAllChainStore];
  83. // remove all the App group key
  84. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  85. } else {
  86. [self settingActiveAccount:recordAccount.account activeUrl:recordAccount.url activeUser:recordAccount.user activePassword:recordAccount.password activeUID:recordAccount.uid activeAccessToken:recordAccount.token typeCloud:recordAccount.typeCloud];
  87. }
  88. // Operation Queue OC-DB Networking
  89. _netQueue = [[NSOperationQueue alloc] init];
  90. _netQueue.name = netQueueName;
  91. _netQueue.maxConcurrentOperationCount = maxConcurrentOperation;
  92. _netQueueDownload = [[NSOperationQueue alloc] init];
  93. _netQueueDownload.name = netQueueDownloadName;
  94. _netQueueDownload.maxConcurrentOperationCount = maxConcurrentOperationDownloadUpload;
  95. _netQueueDownloadWWan = [[NSOperationQueue alloc] init];
  96. _netQueueDownloadWWan.name = netQueueDownloadWWanName;
  97. _netQueueDownloadWWan.maxConcurrentOperationCount = maxConcurrentOperationDownloadUpload;
  98. _netQueueUpload = [[NSOperationQueue alloc] init];
  99. _netQueueUpload.name = netQueueUploadName;
  100. _netQueueUpload.maxConcurrentOperationCount = maxConcurrentOperationDownloadUpload;
  101. _netQueueUploadWWan = [[NSOperationQueue alloc] init];
  102. _netQueueUploadWWan.name = netQueueUploadWWanName;
  103. _netQueueUploadWWan.maxConcurrentOperationCount = maxConcurrentOperationDownloadUpload;
  104. #ifdef CC
  105. // Inizialize DBSession for Dropbox
  106. NSString *appKey = appKeyCryptoCloud;
  107. NSString *appSecret = appSecretCryptoCloud;
  108. DBSession *dbSession = [[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:kDBRootDropbox];
  109. [DBSession setSharedSession:dbSession];
  110. #endif
  111. // Add notification change session
  112. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionChanged:) name:networkingSessionNotification object:nil];
  113. // Inizializzazioni Share
  114. self.sharesID = [[NSMutableDictionary alloc] init];
  115. self.sharesLink = [[NSMutableDictionary alloc] init];
  116. self.sharesUserAndGroup = [[NSMutableDictionary alloc] init];
  117. // Verify Session in progress and Init date task
  118. self.sessionDateLastDownloadTasks = [NSDate date];
  119. self.sessionDateLastUploadTasks = [NSDate date];
  120. self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
  121. // Background Fetch
  122. [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
  123. // Init List
  124. self.listProgressMetadata = [[NSMutableDictionary alloc] init];
  125. self.listChangeTask = [[NSMutableDictionary alloc] init];
  126. self.listMainVC = [[NSMutableDictionary alloc] init];
  127. // Player audio
  128. self.player = [LMMediaPlayerView sharedPlayerView];
  129. self.player.delegate = self;
  130. // ico Image Cache
  131. self.icoImagesCache = [[NSMutableDictionary alloc] init];
  132. // remove tmp & cache
  133. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  134. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  135. for (NSString *file in tmpDirectory) {
  136. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  137. }
  138. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  139. });
  140. // setting Reachable in back
  141. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  142. self.reachability = [Reachability reachabilityForInternetConnection];
  143. self.lastReachability = [self.reachability isReachable];
  144. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
  145. [self.reachability startNotifier];
  146. });
  147. //AV Session
  148. [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
  149. //[[AVAudioSession sharedInstance] setActive:YES error:nil];
  150. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  151. // permission request camera roll
  152. ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
  153. [lib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
  154. //NSLog(@"[LOG] %li",(long)[group numberOfAssets]);
  155. } failureBlock:^(NSError *error) {
  156. if (error.code == ALAssetsLibraryAccessUserDeniedError) {
  157. NSLog(@"[LOG] user denied access, code: %li",(long)error.code);
  158. }else{
  159. NSLog(@"[LOG] Other error code: %li",(long)error.code);
  160. }
  161. }];
  162. // permission request notification
  163. if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
  164. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
  165. [application registerUserNotificationSettings:settings];
  166. }
  167. // it is a device Jailbroken
  168. self.isDeviceJailbroken = isDeviceJailbroken();
  169. [self.window setTintColor:COLOR_BRAND];
  170. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  171. //UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  172. UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
  173. navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  174. splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  175. // Settings TabBar
  176. [self createTabBarController];
  177. // passcode
  178. [[BKPasscodeLockScreenManager sharedManager] setDelegate:self];
  179. dispatch_async(dispatch_get_main_queue(), ^{
  180. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:NO];
  181. });
  182. // Quick Actions
  183. if([[UIApplicationShortcutItem class] respondsToSelector:@selector(new)]) {
  184. [self configDynamicShortcutItems];
  185. UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
  186. if (shortcutItem)
  187. [self handleShortCutItem:shortcutItem];
  188. }
  189. // Start timer Verify Process
  190. self.timerVerifyProcess = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(verifyProcess) userInfo:nil repeats:YES];
  191. return YES;
  192. }
  193. //
  194. // L' applicazione è diventata attiva
  195. //
  196. - (void)applicationDidBecomeActive:(UIApplication *)application
  197. {
  198. // After 5 sec. for wait load app.activeMain start if exists in Table Automatic Upload + All
  199. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  200. if ([CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomatic] > 0)
  201. [app loadTableAutomaticUploadForSelector:selectorUploadAutomatic];
  202. if ([CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomaticAll] > 0)
  203. [app loadTableAutomaticUploadForSelector:selectorUploadAutomaticAll];
  204. });
  205. }
  206. //
  207. // L' applicazione si dimetterà dallo stato di attivo
  208. //
  209. - (void)applicationWillResignActive:(UIApplication *)application
  210. {
  211. [self updateApplicationIconBadgeNumber];
  212. }
  213. //
  214. // L' applicazione entrerà in primo piano (attivo solo dopo il background)
  215. //
  216. - (void)applicationWillEnterForeground:(UIApplication *)application
  217. {
  218. // facciamo partire il timer per il controllo delle sessioni
  219. [self.timerVerifySessionInProgress invalidate];
  220. self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
  221. // refresh active Main
  222. if (_activeMain)
  223. [_activeMain getDataSourceWithReloadTableView];
  224. // Initializations
  225. [self applicationInitialized];
  226. }
  227. //
  228. // L' applicazione è entrata nello sfondo
  229. //
  230. - (void)applicationDidEnterBackground:(UIApplication *)application
  231. {
  232. NSLog(@"[LOG] Enter in Background");
  233. [[CCQuickActions quickActionsManager] closeAll];
  234. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:YES];
  235. if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
  236. __block UIBackgroundTaskIdentifier background_task;
  237. background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
  238. //Clean up code. Tell the system that we are done.
  239. [application endBackgroundTask: background_task];
  240. background_task = UIBackgroundTaskInvalid;
  241. }];
  242. }
  243. }
  244. //
  245. // L'applicazione terminerà
  246. //
  247. - (void)applicationWillTerminate:(UIApplication *)application
  248. {
  249. [MagicalRecord cleanUp];
  250. NSLog(@"[LOG] bye bye, Crypto Cloud !");
  251. }
  252. //
  253. // Method called by the system when all the background task has end
  254. //
  255. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
  256. {
  257. NSLog(@"[LOG] Start completition handler from background - identifier : %@", identifier);
  258. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  259. [[CCNetworking sharedNetworking] automaticDownloadInError];
  260. [[CCNetworking sharedNetworking] automaticUploadInError];
  261. self.backgroundSessionCompletionHandler = completionHandler;
  262. void (^completionHandler)() = self.backgroundSessionCompletionHandler;
  263. self.backgroundSessionCompletionHandler = nil;
  264. completionHandler();
  265. NSLog(@"[LOG] End 25 sec. completition handler - identifier : %@", identifier);
  266. });
  267. }
  268. //
  269. // Application Initialized
  270. //
  271. - (void)applicationInitialized
  272. {
  273. // now
  274. dispatch_async(dispatch_get_main_queue(), ^{
  275. //NSLog(@"[LOG] Read Folder for change Rev");
  276. //[[NSNotificationCenter defaultCenter] postNotificationName:@"readFileSelfFolderRev" object:nil];
  277. });
  278. // 0.5 sec.
  279. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  280. //
  281. NSLog(@"[LOG] Request Server Information");
  282. //
  283. if (_activeMain)
  284. [_activeMain requestServerInformation];
  285. });
  286. // 1 sec.
  287. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  288. NSLog(@"[LOG] Synchronize Favorites");
  289. [[NSNotificationCenter defaultCenter] postNotificationName:@"synchronizedFavorites" object:nil];
  290. NSLog(@"[LOG] Synchronize Folders");
  291. [[CCSynchronization sharedSynchronization] synchronizationFolders];
  292. });
  293. // 1.5 sec.
  294. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  295. NSLog(@"[LOG] Initialize Camera Upload");
  296. [[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:nil];
  297. });
  298. // Initialize Camera Upload
  299. //[[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:@{@"afterDelay": @(2)}];
  300. }
  301. #pragma --------------------------------------------------------------------------------------------
  302. #pragma mark ===== Verify Process 5 seconds =====
  303. #pragma --------------------------------------------------------------------------------------------
  304. - (void)verifyProcess
  305. {
  306. // BACKGROND & FOREGROUND
  307. /* Active/Disactive Graphics Animation Synchronization Folders */
  308. NSArray *records = [CCCoreData getSynchronizedDirectoryActiveAccount:app.activeAccount];
  309. NSMutableArray *directory = [[NSMutableArray alloc] init];
  310. for (TableDirectory *record in records)
  311. [directory addObject:record.serverUrl];
  312. if ([directory count] > 0)
  313. [[CCSynchronization sharedSynchronization] synchronizationAnimationDirectory:directory callViewController:YES];
  314. // ONLY BACKGROUND
  315. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
  316. } else {
  317. // ONLY FOREFROUND
  318. }
  319. }
  320. #pragma --------------------------------------------------------------------------------------------
  321. #pragma mark ===== Setting Active Account =====
  322. #pragma --------------------------------------------------------------------------------------------
  323. - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activePassword:(NSString *)activePassword activeUID:(NSString *)activeUID activeAccessToken:(NSString *)activeAccessToken typeCloud:(NSString *)typeCloud
  324. {
  325. self.activeAccount = activeAccount;
  326. self.activeUrl = activeUrl;
  327. self.activeUser = activeUser;
  328. self.activePassword = activePassword;
  329. self.typeCloud = typeCloud;
  330. self.directoryUser = [CCUtility getDirectoryActiveUser:activeUser activeUrl:activeUrl];
  331. self.activeUID = activeUID;
  332. self.activeAccessToken = activeAccessToken;
  333. }
  334. #pragma --------------------------------------------------------------------------------------------
  335. #pragma mark ===== Quick Actions - ShotcutItem =====
  336. #pragma --------------------------------------------------------------------------------------------
  337. - (void)configDynamicShortcutItems
  338. {
  339. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  340. UIApplicationShortcutIcon *shortcutPhotosIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionPhotos];
  341. UIApplicationShortcutIcon *shortcutUploadClearIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionUploadClear];
  342. UIApplicationShortcutIcon *shortcutUploadEncryptedIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:image_quickActionUploadEncrypted];
  343. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:NSLocalizedString(@"_photo_camera_", nil) localizedSubtitle:nil icon:shortcutPhotosIcon userInfo:nil];
  344. UIApplicationShortcutItem *shortcutFavorite = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.favorite", bundleId] localizedTitle:NSLocalizedString(@"_favorites_", nil) localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeFavorite] userInfo:nil];
  345. UIApplicationShortcutItem *shortcutUploadClear = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.uploadClear", bundleId] localizedTitle:NSLocalizedString(@"_upload_file_", nil) localizedSubtitle:nil icon:shortcutUploadClearIcon userInfo:nil];
  346. UIApplicationShortcutItem *shortcutUploadEncrypted = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.uploadEncrypted", bundleId] localizedTitle:NSLocalizedString(@"_upload_encrypted_file_", nil) localizedSubtitle:nil icon:shortcutUploadEncryptedIcon userInfo:nil];
  347. // add all items to an array
  348. NSArray *items = @[shortcutUploadEncrypted, shortcutUploadClear, shortcutPhotos, shortcutFavorite];
  349. // add the array to our app
  350. [UIApplication sharedApplication].shortcutItems = items;
  351. }
  352. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  353. {
  354. BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];
  355. completionHandler(handledShortCutItem);
  356. }
  357. - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem
  358. {
  359. BOOL handled = NO;
  360. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  361. NSString *shortcutFavorite = [NSString stringWithFormat:@"%@.favorite", bundleId];
  362. NSString *shortcutPhotos = [NSString stringWithFormat:@"%@.photos", bundleId];
  363. NSString *shortcutUploadClear = [NSString stringWithFormat:@"%@.uploadClear", bundleId];
  364. NSString *shortcutUploadEncrypted = [NSString stringWithFormat:@"%@.uploadEncrypted", bundleId];
  365. if ([shortcutItem.type isEqualToString:shortcutUploadClear] && self.activeAccount) {
  366. dispatch_async(dispatch_get_main_queue(), ^{
  367. if (_activeMain) {
  368. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  369. if (splitViewController.isCollapsed) {
  370. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  371. for (UINavigationController *nvc in tbc.viewControllers) {
  372. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  373. [nvc popToRootViewControllerAnimated:NO];
  374. }
  375. [tbc setSelectedIndex:TabBarApplicationIndexFile];
  376. } else {
  377. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  378. [nvcDetail popToRootViewControllerAnimated:NO];
  379. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  380. [tbc setSelectedIndex:TabBarApplicationIndexFile];
  381. }
  382. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  383. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  384. [[CCQuickActions quickActionsManager] startQuickActionsEncrypted:NO viewController:_activeMain];
  385. });
  386. }
  387. });
  388. handled = YES;
  389. }
  390. else if ([shortcutItem.type isEqualToString:shortcutUploadEncrypted] && self.activeAccount) {
  391. dispatch_async(dispatch_get_main_queue(), ^{
  392. if (_activeMain) {
  393. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  394. if (splitViewController.isCollapsed) {
  395. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  396. for (UINavigationController *nvc in tbc.viewControllers) {
  397. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  398. [nvc popToRootViewControllerAnimated:NO];
  399. }
  400. [tbc setSelectedIndex:TabBarApplicationIndexFile];
  401. } else {
  402. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  403. [nvcDetail popToRootViewControllerAnimated:NO];
  404. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  405. [tbc setSelectedIndex:TabBarApplicationIndexFile];
  406. }
  407. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  408. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  409. [[CCQuickActions quickActionsManager] startQuickActionsEncrypted:YES viewController:_activeMain];
  410. });
  411. }
  412. });
  413. handled = YES;
  414. }
  415. else if ([shortcutItem.type isEqualToString:shortcutPhotos] && self.activeAccount) {
  416. dispatch_async(dispatch_get_main_queue(), ^{
  417. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  418. if (splitViewController.isCollapsed) {
  419. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  420. for (UINavigationController *nvc in tbc.viewControllers) {
  421. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  422. [nvc popToRootViewControllerAnimated:NO];
  423. }
  424. [tbc setSelectedIndex:TabBarApplicationIndexPhotos];
  425. } else {
  426. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  427. [nvcDetail popToRootViewControllerAnimated:NO];
  428. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  429. [tbc setSelectedIndex:TabBarApplicationIndexPhotos];
  430. }
  431. });
  432. handled = YES;
  433. }
  434. else if ([shortcutItem.type isEqualToString:shortcutFavorite] && self.activeAccount) {
  435. dispatch_async(dispatch_get_main_queue(), ^{
  436. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  437. if (splitViewController.isCollapsed) {
  438. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  439. for (UINavigationController *nvc in tbc.viewControllers) {
  440. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  441. [nvc popToRootViewControllerAnimated:NO];
  442. if ([nvc.topViewController isKindOfClass:[CCFavorite class]])
  443. [(CCFavorite *)nvc.topViewController forcedSwitchFavorite];
  444. }
  445. [tbc setSelectedIndex:TabBarApplicationIndexFavorite];
  446. } else {
  447. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  448. [nvcDetail popToRootViewControllerAnimated:NO];
  449. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  450. UINavigationController *ncFavorite = [tbc.viewControllers objectAtIndex:TabBarApplicationIndexFavorite];
  451. if ([ncFavorite.topViewController isKindOfClass:[CCFavorite class]])
  452. [(CCFavorite *)ncFavorite.topViewController forcedSwitchFavorite];
  453. [tbc setSelectedIndex:TabBarApplicationIndexFavorite];
  454. }
  455. });
  456. handled = YES;
  457. }
  458. return handled;
  459. }
  460. #pragma --------------------------------------------------------------------------------------------
  461. #pragma mark ===== StatusBar & ApplicationIconBadgeNumber =====
  462. #pragma --------------------------------------------------------------------------------------------
  463. - (void)messageNotification:(NSString *)title description:(NSString *)description visible:(BOOL)visible delay:(NSTimeInterval)delay type:(TWMessageBarMessageType)type
  464. {
  465. title = [NSString stringWithFormat:@"%@\n",[CCUtility localizableBrand:title table:nil]];
  466. dispatch_async(dispatch_get_main_queue(), ^{
  467. if (visible) {
  468. [TWMessageBarManager sharedInstance].styleSheet = self;
  469. [[TWMessageBarManager sharedInstance] showMessageWithTitle:title description:[CCUtility localizableBrand:description table:nil] type:type duration:delay];
  470. } else {
  471. [[TWMessageBarManager sharedInstance] hideAllAnimated:YES];
  472. }
  473. });
  474. }
  475. - (UIColor *)backgroundColorForMessageType:(TWMessageBarMessageType)type
  476. {
  477. UIColor *backgroundColor = nil;
  478. switch (type)
  479. {
  480. case TWMessageBarMessageTypeError:
  481. backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.90];
  482. break;
  483. case TWMessageBarMessageTypeSuccess:
  484. backgroundColor = [UIColor colorWithRed:0.588 green:0.797 blue:0.000 alpha:0.90];
  485. break;
  486. case TWMessageBarMessageTypeInfo:
  487. backgroundColor = COLOR_BRAND_MESSAGE;
  488. break;
  489. default:
  490. break;
  491. }
  492. return backgroundColor;
  493. }
  494. - (UIColor *)strokeColorForMessageType:(TWMessageBarMessageType)type
  495. {
  496. UIColor *strokeColor = nil;
  497. switch (type)
  498. {
  499. case TWMessageBarMessageTypeError:
  500. strokeColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
  501. break;
  502. case TWMessageBarMessageTypeSuccess:
  503. strokeColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
  504. break;
  505. case TWMessageBarMessageTypeInfo:
  506. strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
  507. break;
  508. default:
  509. break;
  510. }
  511. return strokeColor;
  512. }
  513. - (UIImage *)iconImageForMessageType:(TWMessageBarMessageType)type
  514. {
  515. UIImage *iconImage = nil;
  516. switch (type)
  517. {
  518. case TWMessageBarMessageTypeError:
  519. iconImage = [UIImage imageNamed:@"icon-error.png"];
  520. break;
  521. case TWMessageBarMessageTypeSuccess:
  522. iconImage = [UIImage imageNamed:@"icon-success.png"];
  523. break;
  524. case TWMessageBarMessageTypeInfo:
  525. iconImage = [UIImage imageNamed:@"icon-info.png"];
  526. break;
  527. default:
  528. break;
  529. }
  530. return iconImage;
  531. }
  532. #pragma --------------------------------------------------------------------------------------------
  533. #pragma mark ===== TabBarController =====
  534. #pragma --------------------------------------------------------------------------------------------
  535. - (void)createTabBarController
  536. {
  537. UITabBarItem *item;
  538. NSLayoutConstraint *constraint;
  539. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  540. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  541. [CCAspect aspectTabBar:tabBarController.tabBar hidden:NO];
  542. // File
  543. item = [tabBarController.tabBar.items objectAtIndex:TabBarApplicationIndexFile];
  544. [item setTitle:NSLocalizedString(@"_home_", nil)];
  545. item.image = [UIImage imageNamed:image_tabBarFile];
  546. item.selectedImage = [UIImage imageNamed:image_tabBarFile];
  547. // Favorite - Local
  548. item = [tabBarController.tabBar.items objectAtIndex:TabBarApplicationIndexFavorite];
  549. if (app.isLocalStorage) {
  550. [item setTitle:NSLocalizedString(@"_local_storage_", nil)];
  551. item.image = [UIImage imageNamed:image_tabBarLocal];
  552. item.selectedImage = [UIImage imageNamed:image_tabBarLocal];
  553. } else {
  554. [item setTitle:NSLocalizedString(@"_favorites_", nil)];
  555. item.image = [UIImage imageNamed:image_tabBarFavorite];
  556. item.selectedImage = [UIImage imageNamed:image_tabBarFavorite];
  557. }
  558. // Hide (PLUS)
  559. item = [tabBarController.tabBar.items objectAtIndex:TabBarApplicationIndexHide];
  560. item.title = nil;
  561. item.image = nil;
  562. item.enabled = false;
  563. // Photos
  564. item = [tabBarController.tabBar.items objectAtIndex:TabBarApplicationIndexPhotos];
  565. [item setTitle:NSLocalizedString(@"_photo_camera_", nil)];
  566. item.image = [UIImage imageNamed:image_tabBarPhotos];
  567. item.selectedImage = [UIImage imageNamed:image_tabBarPhotos];
  568. // Settings
  569. item = [tabBarController.tabBar.items objectAtIndex:TabBarApplicationIndexSettings];
  570. [item setTitle:NSLocalizedString(@"_settings_", nil)];
  571. item.image = [UIImage imageNamed:image_tabBarSettings];
  572. item.selectedImage = [UIImage imageNamed:image_tabBarSettings];
  573. // Plus Button
  574. UIImage *buttonImage = [UIImage imageNamed:@"Plus"];
  575. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  576. button.tag = 99;
  577. button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
  578. [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
  579. [button setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  580. [button addTarget:self action:@selector(handleTouchTabbarCenter:) forControlEvents:UIControlEventTouchUpInside];
  581. [button setTranslatesAutoresizingMaskIntoConstraints:NO];
  582. [tabBarController.view addSubview:button];
  583. constraint =[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:tabBarController.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
  584. [tabBarController.view addConstraint:constraint];
  585. constraint =[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:tabBarController.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5];
  586. [tabBarController.view addConstraint:constraint];
  587. }
  588. - (void)plusButtonVisibile:(BOOL)visible
  589. {
  590. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  591. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  592. UIButton *buttonPlus = [tabBarController.view viewWithTag:99];
  593. if (buttonPlus) {
  594. if (visible) {
  595. buttonPlus.hidden = false;
  596. } else {
  597. buttonPlus.hidden = true;
  598. }
  599. }
  600. }
  601. - (void)handleTouchTabbarCenter:(id)sender
  602. {
  603. //if (_activeMain)
  604. // [_activeMain addActionTable];
  605. CreateMenu *menu = [[CreateMenu alloc] init];
  606. [menu createMenuPlainWithView:self.window.rootViewController.view];
  607. /*
  608. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.window.rootViewController.view title:nil];
  609. [actionSheet addButtonWithTitle:NSLocalizedString(@"Info", nil)
  610. image:[UIImage imageNamed:@"passcode"]
  611. type:AHKActionSheetButtonTypeDefault
  612. handler:^(AHKActionSheet *as) {
  613. if (_activeMain)
  614. [_activeMain returnCreate:returnCreateFolderPlain];
  615. }];
  616. [actionSheet addButtonWithTitle:NSLocalizedString(@"Add to Favorites", nil)
  617. image:[UIImage imageNamed:@"password"]
  618. type:AHKActionSheetButtonTypeDefault
  619. handler:^(AHKActionSheet *as) {
  620. if (_activeMain)
  621. [_activeMain returnCreate:returnCreateFotoVideoPlain];
  622. }];
  623. [actionSheet show];
  624. */
  625. }
  626. - (void)updateApplicationIconBadgeNumber
  627. {
  628. // Core Data
  629. _queueNunDownload = [[CCCoreData getTableMetadataDownloadAccount:self.activeAccount] count];
  630. _queueNumDownloadWWan = [[CCCoreData getTableMetadataDownloadWWanAccount:self.activeAccount] count];
  631. _queueNumUpload = [[CCCoreData getTableMetadataUploadAccount:self.activeAccount] count];
  632. _queueNumUploadWWan = [[CCCoreData getTableMetadataUploadWWanAccount:self.activeAccount] count];
  633. // netQueueDownload
  634. for (NSOperation *operation in [app.netQueueDownload operations]) {
  635. /*** NEXTCLOUD OWNCLOUD ***/
  636. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  637. if (((OCnetworking *)operation).isExecuting == NO) _queueNunDownload++;
  638. #ifdef CC
  639. /*** DROPBOX ***/
  640. if ([app.typeCloud isEqualToString:typeCloudDropbox])
  641. if (((DBnetworking *)operation).isExecuting == NO) _queueNunDownload++;
  642. #endif
  643. }
  644. // netQueueDownloadWWan
  645. for (NSOperation *operation in [app.netQueueDownloadWWan operations]) {
  646. /*** NEXTCLOUD OWNCLOUD ***/
  647. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  648. if (((OCnetworking *)operation).isExecuting == NO) _queueNumDownloadWWan++;
  649. #ifdef CC
  650. /*** DROPBOX ***/
  651. if ([app.typeCloud isEqualToString:typeCloudDropbox])
  652. if (((DBnetworking *)operation).isExecuting == NO) _queueNumDownloadWWan++;
  653. #endif
  654. }
  655. // netQueueUpload
  656. for (NSOperation *operation in [app.netQueueUpload operations]) {
  657. /*** NEXTCLOUD OWNCLOUD ***/
  658. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  659. if (((OCnetworking *)operation).isExecuting == NO) _queueNumUpload++;
  660. #ifdef CC
  661. /*** DROPBOX ***/
  662. if ([app.typeCloud isEqualToString:typeCloudDropbox])
  663. if (((DBnetworking *)operation).isExecuting == NO) _queueNumUpload++;
  664. #endif
  665. }
  666. // netQueueUploadWWan
  667. for (NSOperation *operation in [app.netQueueUploadWWan operations]) {
  668. /*** NEXTCLOUD OWNCLOUD ***/
  669. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  670. if (((OCnetworking *)operation).isExecuting == NO) _queueNumUploadWWan++;
  671. #ifdef CC
  672. /*** DROPBOX ***/
  673. if ([app.typeCloud isEqualToString:typeCloudDropbox])
  674. if (((DBnetworking *)operation).isExecuting == NO) _queueNumUploadWWan++;
  675. #endif
  676. }
  677. // Total
  678. NSUInteger total = _queueNunDownload + _queueNumDownloadWWan + _queueNumUpload + _queueNumUploadWWan + [CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:nil];
  679. [UIApplication sharedApplication].applicationIconBadgeNumber = total;
  680. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  681. if ([[splitViewController.viewControllers firstObject] isKindOfClass:[UITabBarController class]]) {
  682. UITabBarController *tbc = [splitViewController.viewControllers firstObject];
  683. UITabBarItem *tbItem = [tbc.tabBar.items objectAtIndex:0];
  684. if (total > 0)
  685. [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
  686. else
  687. [tbItem setBadgeValue:nil];
  688. }
  689. }
  690. #pragma --------------------------------------------------------------------------------------------
  691. #pragma mark ===== Media Player Control =====
  692. #pragma --------------------------------------------------------------------------------------------
  693. - (void)remoteControlReceivedWithEvent:(UIEvent *)event
  694. {
  695. switch (event.subtype) {
  696. case UIEventSubtypeRemoteControlPlay:
  697. if (self.player.mediaPlayer) {
  698. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  699. if (self.player.mediaPlayer.nowPlayingItem.title)
  700. [songInfo setObject:self.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  701. if (self.player.mediaPlayer.nowPlayingItem.artist)
  702. [songInfo setObject:self.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  703. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  704. [self.player.mediaPlayer play];
  705. }
  706. break;
  707. case UIEventSubtypeRemoteControlPause:
  708. if (self.player.mediaPlayer) {
  709. [self.player.mediaPlayer pause];
  710. }
  711. break;
  712. case UIEventSubtypeRemoteControlNextTrack:
  713. // handle it break;
  714. case UIEventSubtypeRemoteControlPreviousTrack:
  715. // handle it break;
  716. default:
  717. break;
  718. }
  719. }
  720. - (BOOL)mediaPlayerViewWillStartPlaying:(LMMediaPlayerView *)playerView media:(LMMediaItem *)media
  721. {
  722. return YES;
  723. }
  724. #pragma --------------------------------------------------------------------------------------------
  725. #pragma mark ===== Manager Passcode =====
  726. #pragma --------------------------------------------------------------------------------------------
  727. - (BOOL)lockScreenManagerShouldShowLockScreen:(BKPasscodeLockScreenManager *)aManager
  728. {
  729. // fermiamo la data della sessione
  730. self.sessionePasscodeLock = nil;
  731. // se il block code è a zero esci con NON attivare la richiesta password
  732. if ([[CCUtility getBlockCode] length] == 0) return NO;
  733. // se non c'è attivo un account esci con NON attivare la richiesta password
  734. if ([self.activeAccount length] == 0) return NO;
  735. // se non c'è il passcode esci con NON attivare la richiesta password
  736. if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) return NO;
  737. // se non è attivo il OnlyLockDir esci con NON attivare la richiesta password
  738. if ([CCUtility getOnlyLockDir] && ![CCCoreData isBlockZone:self.serverUrl activeAccount:self.activeAccount]) return NO;
  739. return YES;
  740. }
  741. - (UIViewController *)lockScreenManagerPasscodeViewController:(BKPasscodeLockScreenManager *)aManager
  742. {
  743. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  744. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  745. viewController.delegate = self;
  746. viewController.title = _brand_;
  747. viewController.fromType = CCBKPasscodeFromLockScreen;
  748. viewController.inputViewTitlePassword = YES;
  749. if ([CCUtility getSimplyBlockCode]) {
  750. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  751. viewController.passcodeInputView.maximumLength = 6;
  752. } else {
  753. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  754. viewController.passcodeInputView.maximumLength = 64;
  755. }
  756. viewController.touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  757. viewController.touchIDManager.promptText = [CCUtility localizableBrand:@"_scan_fingerprint_" table:nil];
  758. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  759. return navigationController;
  760. }
  761. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  762. {
  763. [aViewController dismissViewControllerAnimated:YES completion:nil];
  764. // is a lock screen
  765. if (aViewController.fromType == CCBKPasscodeFromLockScreen) {
  766. [aViewController dismissViewControllerAnimated:YES completion:nil];
  767. // start session Passcode Lock
  768. if ([CCCoreData isBlockZone:self.serverUrl activeAccount:self.activeAccount])
  769. self.sessionePasscodeLock = [NSDate date];
  770. }
  771. }
  772. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  773. {
  774. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromInit) {
  775. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  776. //self.lockUntilDate = nil;
  777. //self.failedAttempts = 0;
  778. aResultHandler(YES);
  779. } else aResultHandler(NO);
  780. } else aResultHandler(YES);
  781. }
  782. #pragma --------------------------------------------------------------------------------------------
  783. #pragma mark ===== reachabilityChanged =====
  784. #pragma --------------------------------------------------------------------------------------------
  785. -(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
  786. {
  787. if ([self.reachability isReachable]) {
  788. if (self.lastReachability == NO) {
  789. [self messageNotification:@"_network_available_" description:nil visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  790. if (_activeMain)
  791. [_activeMain performSelector:@selector(requestServerInformation) withObject:nil afterDelay:3];
  792. }
  793. NSLog(@"[LOG] Reachability Changed: Reachable");
  794. self.lastReachability = YES;
  795. } else {
  796. if (self.lastReachability == YES) {
  797. [self messageNotification:@"_network_not_available_" description:nil visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  798. }
  799. NSLog(@"[LOG] Reachability Changed: NOT Reachable");
  800. self.lastReachability = NO;
  801. }
  802. if ([self.reachability isReachableViaWiFi]) NSLog(@"[LOG] Reachability Changed: WiFi");
  803. if ([self.reachability isReachableViaWWAN]) NSLog(@"[LOG] Reachability Changed: WWAn");
  804. [[NSNotificationCenter defaultCenter] postNotificationName:@"setTitleCCMainNOAnimation" object:nil];
  805. }
  806. #pragma --------------------------------------------------------------------------------------------
  807. #pragma mark ===== Fetch =====
  808. #pragma --------------------------------------------------------------------------------------------
  809. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  810. {
  811. NSLog(@"[LOG] Start Fetch");
  812. // Verify new photo
  813. [[NSNotificationCenter defaultCenter] postNotificationName:@"initStateCameraUpload" object:nil];
  814. // after 20 sec verify Re
  815. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  816. [[CCNetworking sharedNetworking] automaticDownloadInError];
  817. [[CCNetworking sharedNetworking] automaticUploadInError];
  818. NSLog(@"[LOG] End Fetch 20 sec.");
  819. });
  820. // after 25 sec
  821. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  822. NSArray *records = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session != NULL) AND (session != '')", self.activeAccount] context:nil];
  823. if ([records count] > 0) {
  824. completionHandler(UIBackgroundFetchResultNewData);
  825. } else {
  826. completionHandler(UIBackgroundFetchResultNoData);
  827. }
  828. NSLog(@"[LOG] End Fetch 25 sec.");
  829. });
  830. }
  831. #pragma --------------------------------------------------------------------------------------------
  832. #pragma mark ===== Operation Networking & Session =====
  833. #pragma --------------------------------------------------------------------------------------------
  834. - (void)cancelAllOperations
  835. {
  836. [_netQueue cancelAllOperations];
  837. [_netQueueDownload cancelAllOperations];
  838. [_netQueueDownloadWWan cancelAllOperations];
  839. [_netQueueUpload cancelAllOperations];
  840. [_netQueueUploadWWan cancelAllOperations];
  841. [self performSelector:@selector(updateApplicationIconBadgeNumber) withObject:nil afterDelay:0.5];
  842. }
  843. - (void)addNetworkingOperationQueue:(NSOperationQueue *)netQueue delegate:(id)delegate metadataNet:(CCMetadataNet *)metadataNet
  844. {
  845. id operation;
  846. BOOL activityIndicator = NO;
  847. // Activity Indicator
  848. if (netQueue == _netQueue)
  849. activityIndicator = YES;
  850. /*** NEXTCLOUD OWNCLOUD ***/
  851. if ([_typeCloud isEqualToString:typeCloudOwnCloud] || [_typeCloud isEqualToString:typeCloudNextcloud])
  852. operation = [[OCnetworking alloc] initWithDelegate:delegate metadataNet:metadataNet withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl withTypeCloud:_typeCloud activityIndicator:activityIndicator];
  853. #ifdef CC
  854. /*** DROPBOX ***/
  855. if ([_typeCloud isEqualToString:typeCloudDropbox])
  856. operation = [[DBnetworking alloc] initWithDelegate:delegate metadataNet:metadataNet withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl withActiveUID:_activeUID withActiveAccessToken:_activeAccessToken activityIndicator:activityIndicator];
  857. #endif
  858. [operation setQueuePriority:metadataNet.priority];
  859. [netQueue addOperation:operation];
  860. }
  861. - (NSMutableArray *)verifyExistsInQueuesDownloadSelector:(NSString *)selector
  862. {
  863. NSMutableArray *metadatasNet = [[NSMutableArray alloc] init];
  864. /*** NEXTCLOUD OWNCLOUD ***/
  865. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  866. for (OCnetworking *operation in [self.netQueueDownload operations])
  867. if ([operation.metadataNet.selector isEqualToString:selector])
  868. [metadatasNet addObject:[operation.metadataNet copy]];
  869. for (OCnetworking *operation in [self.netQueueDownloadWWan operations])
  870. if ([operation.metadataNet.selector isEqualToString:selector])
  871. [metadatasNet addObject:[operation.metadataNet copy]];
  872. }
  873. #ifdef CC
  874. /*** DROPBOX ***/
  875. if ([app.typeCloud isEqualToString:typeCloudDropbox]) {
  876. for (DBnetworking *operation in [self.netQueueDownload operations])
  877. if ([operation.metadataNet.selector isEqualToString:selector])
  878. [metadatasNet addObject:operation.metadataNet];
  879. for (DBnetworking *operation in [self.netQueueDownloadWWan operations])
  880. if ([operation.metadataNet.selector isEqualToString:selector])
  881. [metadatasNet addObject:operation.metadataNet];
  882. }
  883. #endif
  884. return metadatasNet;
  885. }
  886. - (NSMutableArray *)verifyExistsInQueuesUploadSelector:(NSString *)selector
  887. {
  888. NSMutableArray *metadatasNet = [[NSMutableArray alloc] init];
  889. /*** NEXTCLOUD OWNCLOUD ***/
  890. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  891. for (OCnetworking *operation in [self.netQueueUpload operations])
  892. if ([operation.metadataNet.selector isEqualToString:selector])
  893. [metadatasNet addObject:[operation.metadataNet copy]];
  894. for (OCnetworking *operation in [self.netQueueUploadWWan operations])
  895. if ([operation.metadataNet.selector isEqualToString:selector])
  896. [metadatasNet addObject:[operation.metadataNet copy]];
  897. }
  898. #ifdef CC
  899. /*** DROPBOX ***/
  900. if ([app.typeCloud isEqualToString:typeCloudDropbox]) {
  901. for (DBnetworking *operation in [self.netQueueUpload operations])
  902. if ([operation.metadataNet.selector isEqualToString:selector])
  903. [metadatasNet addObject:operation.metadataNet];
  904. for (DBnetworking *operation in [self.netQueueUploadWWan operations])
  905. if ([operation.metadataNet.selector isEqualToString:selector])
  906. [metadatasNet addObject:operation.metadataNet];
  907. }
  908. #endif
  909. return metadatasNet;
  910. }
  911. - (void)loadTableAutomaticUploadForSelector:(NSString *)selector
  912. {
  913. // Only one
  914. if ([[self verifyExistsInQueuesUploadSelector:selector] count] > 1)
  915. return;
  916. // Verify num error if selectorUploadAutomaticAll
  917. if ([selector isEqualToString:selectorUploadAutomaticAll]) {
  918. NSUInteger count = [TableMetadata MR_countOfEntitiesWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier == %i) OR (sessionTaskIdentifierPlist == %i))", app.activeAccount, selectorUploadAutomaticAll,taskIdentifierError, taskIdentifierError]];
  919. #ifdef DEBUG
  920. NSArray *records = [[NSArray alloc] init];
  921. records = [TableMetadata MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (sessionSelector == %@) AND ((sessionTaskIdentifier == %i) OR (sessionTaskIdentifierPlist == %i))", app.activeAccount, selectorUploadAutomaticAll,taskIdentifierError, taskIdentifierError]];
  922. #endif
  923. if (count >= 10) {
  924. [app messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  925. return;
  926. }
  927. }
  928. // Add Network queue
  929. CCMetadataNet *metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selector context:nil];
  930. if (metadataNet) {
  931. NSOperationQueue *queue;
  932. if ([metadataNet.session containsString:@"wwan"])
  933. queue = app.netQueueUploadWWan;
  934. else
  935. queue = app.netQueueUpload;
  936. [self addNetworkingOperationQueue:queue delegate:app.activeMain metadataNet:metadataNet];
  937. }
  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:timerVerifySession], [self.sessionDateLastUploadTasks dateByAddingTimeInterval:timerVerifySession]);
  945. if ([[NSDate date] compare:[self.sessionDateLastDownloadTasks dateByAddingTimeInterval:timerVerifySession]] == NSOrderedDescending) {
  946. callVerifyDownload = YES;
  947. [[CCNetworking sharedNetworking] verifyDownloadInProgress];
  948. }
  949. if ([[NSDate date] compare:[self.sessionDateLastUploadTasks dateByAddingTimeInterval: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. if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"stopUpload"]) {
  998. // sessionTaskIdentifier on Stop
  999. [CCCoreData setMetadataSession:nil sessionError:@"" sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:taskIdentifierStop sessionTaskIdentifierPlist:taskIdentifierDone predicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, self.activeAccount] context:nil];
  1000. }
  1001. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"reloadUpload"]) {
  1002. // V 1.8 if upload_session_wwan change in upload_session
  1003. if ([metadata.session isEqualToString:upload_session_wwan])
  1004. metadata.session = upload_session;
  1005. [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:taskStatusResume];
  1006. }
  1007. else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"reloadDownload"]) {
  1008. BOOL downloadData = NO, downloadPlist = NO;
  1009. if (metadata.sessionTaskIdentifier != taskIdentifierDone) downloadData = YES;
  1010. if (metadata.sessionTaskIdentifierPlist != taskIdentifierDone) downloadPlist = YES;
  1011. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  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:download_session taskStatus: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:taskIdentifierDone sessionTaskIdentifierPlist: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. // Detail
  1030. if (_activeDetail)
  1031. [_activeDetail progressTask:nil serverUrl:nil cryptated:NO progress:0];
  1032. // Refresh
  1033. if (_activeMain && [_listChangeTask count] == 0)
  1034. [_activeMain getDataSourceWithReloadTableView:metadata.directoryID fileID:nil selector:nil];
  1035. }
  1036. - (void)dropAutomaticUploadWithSelector:(NSString *)selector
  1037. {
  1038. [CCCoreData flushTableAutomaticUploadAccount:self.activeAccount selector:selector];
  1039. // Update icon badge number
  1040. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1041. [self updateApplicationIconBadgeNumber];
  1042. });
  1043. }
  1044. #pragma --------------------------------------------------------------------------------------------
  1045. #pragma mark ===== Dropbox =====
  1046. #pragma --------------------------------------------------------------------------------------------
  1047. #ifdef CC
  1048. - (void)sessionDidReceiveAuthorizationFailure:(DBSession*)session userId:(NSString *)userId
  1049. {
  1050. [[NSNotificationCenter defaultCenter] postNotificationName:@"messageLoginIncorrect" object:nil];
  1051. }
  1052. - (void)restClient:(DBRestClient *)client loadedAccountInfo:(DBAccountInfo *)info
  1053. {
  1054. NSString *account = [NSString stringWithFormat:@"%@ %@", [info email], typeCloudDropbox];
  1055. [CCCoreData deleteAccount:account];
  1056. // new account
  1057. [CCCoreData addAccount:account url:@"https://www.dropbox.com" user:[info email] password:nil uid:info.userId typeCloud:typeCloudDropbox];
  1058. TableAccount *tableAccount = [CCCoreData setActiveAccount:account];
  1059. if (tableAccount)
  1060. [self settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password activeUID:tableAccount.uid activeAccessToken:tableAccount.token typeCloud:tableAccount.typeCloud];
  1061. NSString *uuid = [CCUtility getUUID];
  1062. NSString *passcode = [CCUtility getKeyChainPasscodeForUUID:uuid];
  1063. // update ManageAccount
  1064. [[NSNotificationCenter defaultCenter] postNotificationName:@"updateFormManageAccount" object:nil];
  1065. // Login correct
  1066. if ([passcode length] > 0 && [self.activeAccount length] > 0)
  1067. [[NSNotificationCenter defaultCenter] postNotificationName:@"messageLoginCorrect" object:nil];
  1068. }
  1069. #endif
  1070. #pragma --------------------------------------------------------------------------------------------
  1071. #pragma mark ===== Open CCUploadFromOtherUpp =====
  1072. #pragma --------------------------------------------------------------------------------------------
  1073. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  1074. {
  1075. return YES;
  1076. }
  1077. // Method called from iOS system to send a file from other app.
  1078. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  1079. {
  1080. NSLog(@"[LOG] URL from %@ application", sourceApplication);
  1081. NSLog(@"[LOG] the path is: %@", url.path);
  1082. #ifdef CC
  1083. /*************************************** DROPBOX *********************************/
  1084. if ([[DBSession sharedSession] handleOpenURL:url]) {
  1085. NSString *query = url.query;
  1086. if ([[url absoluteString] rangeOfString:@"cancel"].location == NSNotFound) {
  1087. NSDictionary *urlData = [DBSession parseURLParams:query];
  1088. NSString *uid = [urlData objectForKey:@"uid"];
  1089. if ([[[DBSession sharedSession] userIds] containsObject:uid]) {
  1090. self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession] userId:uid];
  1091. self.restClient.delegate = self;
  1092. [self.restClient loadAccountInfo];
  1093. }
  1094. } else {
  1095. // user cancelled the login
  1096. [[NSNotificationCenter defaultCenter] postNotificationName:@"messageLoginIncorrect" object:nil];
  1097. }
  1098. return YES;
  1099. }
  1100. /*********************************************************************************/
  1101. #endif
  1102. NSArray *splitedUrl = [url.path componentsSeparatedByString:@"/"];
  1103. self.fileNameUpload = [NSString stringWithFormat:@"%@",[splitedUrl objectAtIndex:([splitedUrl count]-1)]];
  1104. NSString *passcode = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  1105. if (self.activeAccount && [passcode length]) {
  1106. [[NSFileManager defaultManager]moveItemAtPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] stringByAppendingPathComponent:self.fileNameUpload] toPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, self.fileNameUpload] error:nil];
  1107. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  1108. UINavigationController *splitNavigationController = [splitViewController.viewControllers firstObject];
  1109. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
  1110. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1111. [splitNavigationController presentViewController:navigationController animated:YES completion:nil];
  1112. });
  1113. }
  1114. // remove from InBox
  1115. [[NSFileManager defaultManager] removeItemAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] error:nil];
  1116. return YES;
  1117. }
  1118. #pragma --------------------------------------------------------------------------------------------
  1119. #pragma mark ===== UPGRADE =====
  1120. #pragma --------------------------------------------------------------------------------------------
  1121. - (void)upgrade
  1122. {
  1123. #ifdef DEBUG
  1124. // [CCCoreData flushTableGPS];
  1125. // [CCCoreData setGeoInformationLocalNull];
  1126. #endif
  1127. NSString *actualVersion = [CCUtility getVersionCryptoCloud];
  1128. /* ---------------------- UPGRADE VERSION ----------------------- */
  1129. if (([actualVersion compare:@"2.13" options:NSNumericSearch] == NSOrderedAscending)) {
  1130. [CCCoreData flushTableDirectoryAccount:nil];
  1131. [CCCoreData flushTableLocalFileAccount:nil];
  1132. [CCCoreData flushTableMetadataAccount:nil];
  1133. }
  1134. if (([actualVersion compare:@"2.15" options:NSNumericSearch] == NSOrderedAscending)) {
  1135. [CCCoreData flushTableGPS];
  1136. [CCCoreData setGeoInformationLocalNull];
  1137. }
  1138. }
  1139. @end