AppDelegate.m 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. //
  2. // AppDelegate.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2017 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 "CCGraphics.h"
  28. #import "CCPhotos.h"
  29. #import "CCSynchronize.h"
  30. #import "CCMain.h"
  31. #import "CCDetail.h"
  32. #import <Fabric/Fabric.h>
  33. #import <Crashlytics/Crashlytics.h>
  34. #import "JDStatusBarNotification.h"
  35. #import "NCBridgeSwift.h"
  36. #import "NCAutoUpload.h"
  37. #import "Firebase.h"
  38. #import "NCPushNotification.h"
  39. @interface AppDelegate () <UNUserNotificationCenterDelegate, FIRMessagingDelegate>
  40. @end
  41. @implementation AppDelegate
  42. + (void)initialize
  43. {
  44. [iRate sharedInstance].daysUntilPrompt = 5;
  45. [iRate sharedInstance].usesUntilPrompt = 5;
  46. [iRate sharedInstance].promptForNewVersionIfUserRated = true;
  47. [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent": [CCUtility getUserAgent]}];
  48. //enable preview mode
  49. //[iRate sharedInstance].previewMode = YES;
  50. }
  51. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  52. {
  53. NSString *path;
  54. NSURL *dirGroup = [CCUtility getDirectoryGroup];
  55. NSLog(@"[LOG] Start program group -----------------");
  56. NSLog(@"%@", [dirGroup path]);
  57. NSLog(@"[LOG] Start program application -----------");
  58. NSLog(@"%@", [[CCUtility getDirectoryDocuments] stringByDeletingLastPathComponent]);
  59. NSLog(@"[LOG] -------------------------------------");
  60. // create Directory Documents
  61. path = [CCUtility getDirectoryDocuments];
  62. if (![[NSFileManager defaultManager] fileExistsAtPath: path])
  63. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  64. // create Directory audio => Library, Application Support, audio
  65. path = [CCUtility getDirectoryAudio];
  66. if (![[NSFileManager defaultManager] fileExistsAtPath: path])
  67. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  68. // create Directory database Nextcloud
  69. path = [[dirGroup URLByAppendingPathComponent:k_appDatabaseNextcloud] path];
  70. if (![[NSFileManager defaultManager] fileExistsAtPath:path])
  71. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  72. [[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:path error:nil];
  73. // create Directory User Data
  74. path = [[dirGroup URLByAppendingPathComponent:k_appUserData] path];
  75. if (![[NSFileManager defaultManager] fileExistsAtPath:path])
  76. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  77. // create Directory Provider Storage
  78. path = [CCUtility getDirectoryProviderStorage];
  79. if (![[NSFileManager defaultManager] fileExistsAtPath: path])
  80. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  81. // Verify upgrade
  82. if ([self upgrade]) {
  83. // Set account, if no exists clear all
  84. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  85. if (account == nil) {
  86. // remove all the keys Chain
  87. [CCUtility deleteAllChainStore];
  88. // remove all the App group key
  89. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  90. } else {
  91. [self settingActiveAccount:account.account activeUrl:account.url activeUser:account.user activeUserID:account.userID activePassword:account.password];
  92. }
  93. }
  94. #ifdef DEBUG
  95. NSLog(@"[LOG] Copy DB on Documents directory");
  96. NSString *atPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [[dirGroup URLByAppendingPathComponent:k_appDatabaseNextcloud] path]];
  97. NSString *toPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [CCUtility getDirectoryDocuments]];
  98. [[NSFileManager defaultManager] removeItemAtPath:toPathDB error:nil];
  99. [[NSFileManager defaultManager] copyItemAtPath:atPathDB toPath:toPathDB error:nil];
  100. #endif
  101. // Operation Queue OC Networking
  102. _netQueue = [[NSOperationQueue alloc] init];
  103. _netQueue.name = k_queue;
  104. _netQueue.maxConcurrentOperationCount = k_maxConcurrentOperation;
  105. // UserDefaults
  106. self.ncUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[NCBrandOptions sharedInstance].capabilitiesGroups];
  107. // Initialization Share
  108. self.sharesID = [NSMutableDictionary new];
  109. self.sharesLink = [NSMutableDictionary new];
  110. self.sharesUserAndGroup = [NSMutableDictionary new];
  111. // Filter fileID
  112. self.filterFileID = [NSMutableArray new];
  113. // Initialization Notification
  114. self.listOfNotifications = [NSMutableArray new];
  115. // Background Fetch
  116. [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
  117. // Initialization List
  118. self.listProgressMetadata = [[NSMutableDictionary alloc] init];
  119. self.listMainVC = [[NSMutableDictionary alloc] init];
  120. // Firebase - Push Notification
  121. @try {
  122. [FIRApp configure];
  123. } @catch (NSException *exception) {
  124. NSLog(@"[LOG] Something went wrong while configuring Firebase");
  125. }
  126. if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
  127. UIUserNotificationType allNotificationTypes =(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
  128. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
  129. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  130. } else {
  131. // iOS 10 or later
  132. #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  133. // For iOS 10 display notification (sent via APNS)
  134. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  135. UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  136. [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
  137. }];
  138. #endif
  139. }
  140. [application registerForRemoteNotifications];
  141. [FIRMessaging messaging].delegate = self;
  142. // setting Reachable in back
  143. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  144. self.reachability = [Reachability reachabilityForInternetConnection];
  145. self.lastReachability = [self.reachability isReachable];
  146. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
  147. [self.reachability startNotifier];
  148. });
  149. //AV Session
  150. [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
  151. //[[AVAudioSession sharedInstance] setActive:YES error:nil];
  152. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  153. // How to hide UINavigationBar 1px bottom line < iOS 11
  154. [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  155. [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
  156. // passcode
  157. [[BKPasscodeLockScreenManager sharedManager] setDelegate:self];
  158. dispatch_async(dispatch_get_main_queue(), ^{
  159. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:NO];
  160. });
  161. // Quick Actions
  162. if([[UIApplicationShortcutItem class] respondsToSelector:@selector(new)]) {
  163. [self configDynamicShortcutItems];
  164. UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
  165. if (shortcutItem)
  166. [self handleShortCutItem:shortcutItem];
  167. }
  168. // Start Timer
  169. self.timerProcessAutoDownloadUpload = [NSTimer scheduledTimerWithTimeInterval:k_timerProcessAutoDownloadUpload target:self selector:@selector(loadAutoDownloadUpload) userInfo:nil repeats:YES];
  170. self.timerUpdateApplicationIconBadgeNumber = [NSTimer scheduledTimerWithTimeInterval:k_timerUpdateApplicationIconBadgeNumber target:self selector:@selector(updateApplicationIconBadgeNumber) userInfo:nil repeats:YES];
  171. // Registration Push Notification
  172. UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
  173. UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
  174. [application registerUserNotificationSettings:notificationSettings];
  175. // Fabric
  176. [Fabric with:@[[Crashlytics class]]];
  177. [self logUser];
  178. return YES;
  179. }
  180. //
  181. // L' applicazione si dimetterà dallo stato di attivo
  182. //
  183. - (void)applicationWillResignActive:(UIApplication *)application
  184. {
  185. [_activeMain closeAllMenu];
  186. [self updateApplicationIconBadgeNumber];
  187. }
  188. //
  189. // L' applicazione entrerà in primo piano (attivo solo dopo il background)
  190. //
  191. - (void)applicationWillEnterForeground:(UIApplication *)application
  192. {
  193. // Test Maintenance
  194. if (self.activeAccount.length == 0 || self.maintenanceMode)
  195. return;
  196. NSLog(@"[LOG] Request Service Server Nextcloud");
  197. [[NCService sharedInstance] startRequestServicesServer];
  198. NSLog(@"[LOG] Initialize Auto upload");
  199. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  200. }
  201. //
  202. // L' applicazione entrerà in primo piano (attivo sempre)
  203. //
  204. - (void)applicationDidBecomeActive:(UIApplication *)application
  205. {
  206. // Test Maintenance
  207. if (self.activeAccount.length == 0 || self.maintenanceMode)
  208. return;
  209. // middelware ping
  210. if ([[NCBrandOptions sharedInstance] use_middlewarePing]) {
  211. NSLog(@"[LOG] Middleware Ping");
  212. [[NCService sharedInstance] middlewarePing];
  213. }
  214. // Test error task upload / download
  215. [self verifyInternalErrorDownloadingUploading];
  216. }
  217. //
  218. // L' applicazione è entrata nello sfondo
  219. //
  220. - (void)applicationDidEnterBackground:(UIApplication *)application
  221. {
  222. NSLog(@"[LOG] Enter in Background");
  223. [[CCQuickActions quickActionsManager] closeAll];
  224. [[BKPasscodeLockScreenManager sharedManager] showLockScreen:YES];
  225. if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
  226. __block UIBackgroundTaskIdentifier background_task;
  227. background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
  228. //Clean up code. Tell the system that we are done.
  229. [application endBackgroundTask: background_task];
  230. background_task = UIBackgroundTaskInvalid;
  231. }];
  232. }
  233. }
  234. //
  235. // L'applicazione terminerà
  236. //
  237. - (void)applicationWillTerminate:(UIApplication *)application
  238. {
  239. NSLog(@"[LOG] bye bye, Nextcloud !");
  240. }
  241. #pragma --------------------------------------------------------------------------------------------
  242. #pragma mark ===== Login =====
  243. #pragma --------------------------------------------------------------------------------------------
  244. - (void)openLoginView:(id)delegate loginType:(NSInteger)loginType selector:(NSInteger)selector
  245. {
  246. BOOL loginWebFlow = NO;
  247. @synchronized (self) {
  248. // only for personalized LoginWeb [customer]
  249. if ([NCBrandOptions sharedInstance].use_login_web_personalized) {
  250. if (_activeLoginWeb == nil) {
  251. _activeLoginWeb = [CCLoginWeb new];
  252. _activeLoginWeb.delegate = delegate;
  253. _activeLoginWeb.loginType = loginType;
  254. _activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginBaseUrl];
  255. dispatch_async(dispatch_get_main_queue(), ^ {
  256. [_activeLoginWeb presentModalWithDefaultTheme:delegate];
  257. });
  258. }
  259. return;
  260. }
  261. // ------------------- Nextcloud -------------------------
  262. //
  263. // Login flow : LoginWeb
  264. if (loginType == k_login_Modify_Password) {
  265. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  266. if (account.loginFlow)
  267. loginWebFlow = YES;
  268. }
  269. if (loginWebFlow || selector == k_intro_signup) {
  270. if (_activeLoginWeb == nil) {
  271. _activeLoginWeb = [CCLoginWeb new];
  272. _activeLoginWeb.delegate = delegate;
  273. _activeLoginWeb.loginType = loginType;
  274. if (selector == k_intro_signup) {
  275. _activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginPreferredProviders];
  276. } else {
  277. _activeLoginWeb.urlBase = self.activeUrl;
  278. }
  279. dispatch_async(dispatch_get_main_queue(), ^ {
  280. [_activeLoginWeb presentModalWithDefaultTheme:delegate];
  281. });
  282. }
  283. } else {
  284. if (_activeLogin == nil) {
  285. _activeLogin = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
  286. _activeLogin.delegate = delegate;
  287. _activeLogin.loginType = loginType;
  288. dispatch_async(dispatch_get_main_queue(), ^ {
  289. [delegate presentViewController:_activeLogin animated:YES completion:nil];
  290. });
  291. }
  292. }
  293. }
  294. }
  295. #pragma --------------------------------------------------------------------------------------------
  296. #pragma mark ===== Setting Active Account for all APP =====
  297. #pragma --------------------------------------------------------------------------------------------
  298. - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activeUserID:(NSString *)activeUserID activePassword:(NSString *)activePassword
  299. {
  300. self.activeAccount = activeAccount;
  301. self.activeUrl = activeUrl;
  302. self.activeUser = activeUser;
  303. self.activeUserID = activeUserID;
  304. self.activePassword = activePassword;
  305. // Setting Account to CCNetworking
  306. [[CCNetworking sharedNetworking] settingAccount];
  307. }
  308. #pragma --------------------------------------------------------------------------------------------
  309. #pragma mark ===== Push Notification =====
  310. #pragma --------------------------------------------------------------------------------------------
  311. - (void)subscribingNextcloudServerPushNotification
  312. {
  313. // test
  314. if (self.activeAccount.length == 0)
  315. return;
  316. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:self.activeUser withUserID:self.activeUserID withPassword:self.activePassword withUrl:self.activeUrl];
  317. [[NCPushNotification sharedInstance] generatePushNotificationsKeyPair];
  318. NSString *pushToken = [CCUtility getPushNotificationToken];
  319. NSString *pushTokenHash = [[NCEndToEndEncryption sharedManager] createSHA512:pushToken];
  320. NSString *devicePublicKey = [[NSString alloc] initWithData:[NCPushNotification sharedInstance].ncPNPublicKey encoding:NSUTF8StringEncoding];
  321. [ocNetworking subscribingPushNotificationServer:self.activeUrl pushToken:pushToken Hash:pushTokenHash devicePublicKey:devicePublicKey success:^{
  322. NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
  323. } failure:^(NSString *message, NSInteger errorCode) {
  324. NSLog(@"[LOG] Error while subscribing to Push Notification server.");
  325. }];
  326. }
  327. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
  328. {
  329. //Called when a notification is delivered to a foreground app.
  330. completionHandler(UNNotificationPresentationOptionAlert);
  331. }
  332. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler
  333. {
  334. //Called to let your app know which action was selected by the user for a given notification.
  335. NSString *message = [response.notification.request.content.userInfo objectForKey:@"subject"];
  336. if (message && [NCPushNotification sharedInstance].ncPNPrivateKey) {
  337. NSString *decryptedMessage = [[NCPushNotification sharedInstance] decryptPushNotification:message withDevicePrivateKey:[NCPushNotification sharedInstance].ncPNPrivateKey];
  338. if (decryptedMessage) {
  339. }
  340. }
  341. completionHandler();
  342. }
  343. #pragma FIREBASE
  344. - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken
  345. {
  346. NSLog(@"FCM registration token: %@", fcmToken);
  347. [CCUtility setPushNotificationToken:fcmToken];
  348. [self subscribingNextcloudServerPushNotification];
  349. }
  350. #pragma --------------------------------------------------------------------------------------------
  351. #pragma mark ===== Quick Actions - ShotcutItem =====
  352. #pragma --------------------------------------------------------------------------------------------
  353. - (void)configDynamicShortcutItems
  354. {
  355. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  356. UIApplicationShortcutIcon *shortcutPhotosIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"quickActionPhotos"];
  357. UIApplicationShortcutIcon *shortcutUploadIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"quickActionUpload"];
  358. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:NSLocalizedString(@"_photo_camera_", nil) localizedSubtitle:nil icon:shortcutPhotosIcon userInfo:nil];
  359. UIApplicationShortcutItem *shortcutUpload = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.upload", bundleId] localizedTitle:NSLocalizedString(@"_upload_file_", nil) localizedSubtitle:nil icon:shortcutUploadIcon userInfo:nil];
  360. // add the array to our app
  361. if (shortcutUpload && shortcutPhotos)
  362. [UIApplication sharedApplication].shortcutItems = @[shortcutUpload, shortcutPhotos];
  363. }
  364. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  365. {
  366. BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];
  367. completionHandler(handledShortCutItem);
  368. }
  369. - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem
  370. {
  371. BOOL handled = NO;
  372. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  373. NSString *shortcutPhotos = [NSString stringWithFormat:@"%@.photos", bundleId];
  374. NSString *shortcutUpload = [NSString stringWithFormat:@"%@.upload", bundleId];
  375. NSString *shortcutUploadEncrypted = [NSString stringWithFormat:@"%@.uploadEncrypted", bundleId];
  376. if ([shortcutItem.type isEqualToString:shortcutUpload] && self.activeAccount) {
  377. dispatch_async(dispatch_get_main_queue(), ^{
  378. if (_activeMain) {
  379. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  380. if (splitViewController.isCollapsed) {
  381. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  382. for (UINavigationController *nvc in tbc.viewControllers) {
  383. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  384. [nvc popToRootViewControllerAnimated:NO];
  385. }
  386. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  387. } else {
  388. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  389. [nvcDetail popToRootViewControllerAnimated:NO];
  390. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  391. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  392. }
  393. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  394. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  395. [[CCQuickActions quickActionsManager] startQuickActionsViewController:_activeMain];
  396. });
  397. }
  398. });
  399. handled = YES;
  400. }
  401. else if ([shortcutItem.type isEqualToString:shortcutUploadEncrypted] && self.activeAccount) {
  402. dispatch_async(dispatch_get_main_queue(), ^{
  403. if (_activeMain) {
  404. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  405. if (splitViewController.isCollapsed) {
  406. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  407. for (UINavigationController *nvc in tbc.viewControllers) {
  408. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  409. [nvc popToRootViewControllerAnimated:NO];
  410. }
  411. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  412. } else {
  413. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  414. [nvcDetail popToRootViewControllerAnimated:NO];
  415. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  416. [tbc setSelectedIndex: k_tabBarApplicationIndexFile];
  417. }
  418. [_activeMain.navigationController popToRootViewControllerAnimated:NO];
  419. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  420. [[CCQuickActions quickActionsManager] startQuickActionsViewController:_activeMain];
  421. });
  422. }
  423. });
  424. handled = YES;
  425. }
  426. else if ([shortcutItem.type isEqualToString:shortcutPhotos] && self.activeAccount) {
  427. dispatch_async(dispatch_get_main_queue(), ^{
  428. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  429. if (splitViewController.isCollapsed) {
  430. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  431. for (UINavigationController *nvc in tbc.viewControllers) {
  432. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  433. [nvc popToRootViewControllerAnimated:NO];
  434. }
  435. [tbc setSelectedIndex: k_tabBarApplicationIndexPhotos];
  436. } else {
  437. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  438. [nvcDetail popToRootViewControllerAnimated:NO];
  439. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  440. [tbc setSelectedIndex: k_tabBarApplicationIndexPhotos];
  441. }
  442. });
  443. handled = YES;
  444. }
  445. return handled;
  446. }
  447. #pragma --------------------------------------------------------------------------------------------
  448. #pragma mark ===== StatusBar & ApplicationIconBadgeNumber =====
  449. #pragma --------------------------------------------------------------------------------------------
  450. - (void)messageNotification:(NSString *)title description:(NSString *)description visible:(BOOL)visible delay:(NSTimeInterval)delay type:(TWMessageBarMessageType)type errorCode:(NSInteger)errorcode
  451. {
  452. static NSInteger errorCodePrev = 0;
  453. dispatch_async(dispatch_get_main_queue(), ^{
  454. if (visible) {
  455. switch (errorcode) {
  456. // JDStatusBarNotification
  457. case kCFURLErrorNotConnectedToInternet :
  458. if (errorCodePrev != errorcode)
  459. [JDStatusBarNotification showWithStatus:NSLocalizedString(title, nil) dismissAfter:delay styleName:JDStatusBarStyleDefault];
  460. errorCodePrev = errorcode;
  461. break;
  462. // TWMessageBarManager
  463. default:
  464. if (description.length > 0) {
  465. [TWMessageBarManager sharedInstance].styleSheet = self;
  466. [[TWMessageBarManager sharedInstance] showMessageWithTitle:[NSString stringWithFormat:@"%@\n", NSLocalizedString(title, nil)] description:NSLocalizedString(description, nil) type:type duration:delay];
  467. }
  468. break;
  469. }
  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 = [NCBrandColor sharedInstance].brand;
  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. - (void)updateApplicationIconBadgeNumber
  533. {
  534. // Test Maintenance
  535. if (self.maintenanceMode)
  536. return;
  537. NSInteger counterDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status = %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading] sorted:@"fileName" ascending:true] count];
  538. NSInteger counterUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d OR status == %d)", self.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:@"fileName" ascending:true] count];
  539. NSInteger total = counterDownload + counterUpload;
  540. [UIApplication sharedApplication].applicationIconBadgeNumber = total;
  541. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  542. if ([[splitViewController.viewControllers firstObject] isKindOfClass:[UITabBarController class]]) {
  543. UITabBarController *tbc = [splitViewController.viewControllers firstObject];
  544. UITabBarItem *tbItem = [tbc.tabBar.items objectAtIndex:0];
  545. if (total > 0) {
  546. [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
  547. } else {
  548. [tbItem setBadgeValue:nil];
  549. }
  550. }
  551. }
  552. #pragma --------------------------------------------------------------------------------------------
  553. #pragma mark ===== TabBarController =====
  554. #pragma --------------------------------------------------------------------------------------------
  555. - (void)createTabBarController:(UITabBarController *)tabBarController
  556. {
  557. UITabBarItem *item;
  558. NSLayoutConstraint *constraint;
  559. CGFloat multiplier = 0;
  560. CGFloat safeAreaBottom = 0;
  561. if (@available(iOS 11, *)) {
  562. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom/2;
  563. }
  564. [self aspectTabBar:tabBarController.tabBar hidden:NO];
  565. // File
  566. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
  567. [item setTitle:NSLocalizedString(@"_home_", nil)];
  568. item.image = [UIImage imageNamed:@"folder"];
  569. item.selectedImage = [UIImage imageNamed:@"folder"];
  570. // Favorites
  571. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFavorite];
  572. [item setTitle:NSLocalizedString(@"_favorites_", nil)];
  573. item.image = [UIImage imageNamed:@"favorite"];
  574. item.selectedImage = [UIImage imageNamed:@"favorite"];
  575. // (PLUS)
  576. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexPlusHide];
  577. item.title = @"";
  578. item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarPlus"] multiplier:3 color:[UIColor clearColor]];
  579. item.enabled = false;
  580. // Photos
  581. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexPhotos];
  582. [item setTitle:NSLocalizedString(@"_photo_camera_", nil)];
  583. item.image = [UIImage imageNamed:@"photos"];
  584. item.selectedImage = [UIImage imageNamed:@"photos"];
  585. // More
  586. item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexMore];
  587. [item setTitle:NSLocalizedString(@"_more_", nil)];
  588. item.image = [UIImage imageNamed:@"tabBarMore"];
  589. item.selectedImage = [UIImage imageNamed:@"tabBarMore"];
  590. // Plus Button
  591. UIImage *buttonImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarPlus"] multiplier:3 color:[NCBrandColor sharedInstance].brandElement];
  592. UIButton *buttonPlus = [UIButton buttonWithType:UIButtonTypeCustom];
  593. buttonPlus.tag = 99;
  594. [buttonPlus setBackgroundImage:buttonImage forState:UIControlStateNormal];
  595. [buttonPlus setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  596. [buttonPlus addTarget:self action:@selector(handleTouchTabbarCenter:) forControlEvents:UIControlEventTouchUpInside];
  597. [buttonPlus setTranslatesAutoresizingMaskIntoConstraints:NO];
  598. [tabBarController.tabBar addSubview:buttonPlus];
  599. multiplier = 1.0;
  600. // X
  601. constraint =[NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterX multiplier:multiplier constant:0];
  602. [tabBarController.view addConstraint:constraint];
  603. // Y
  604. if (safeAreaBottom == 0) {
  605. constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterY multiplier:multiplier constant:0];
  606. } else {
  607. constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:+5];
  608. }
  609. [tabBarController.view addConstraint:constraint];
  610. multiplier = 0.8 * (tabBarController.tabBar.frame.size.height - safeAreaBottom) / tabBarController.tabBar.frame.size.height;
  611. // Width
  612. constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeHeight multiplier:multiplier constant:0];
  613. [tabBarController.view addConstraint:constraint];
  614. // Height
  615. constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeHeight multiplier:multiplier constant:0];
  616. [tabBarController.view addConstraint:constraint];
  617. }
  618. - (void)aspectNavigationControllerBar:(UINavigationBar *)nav online:(BOOL)online hidden:(BOOL)hidden
  619. {
  620. nav.translucent = NO;
  621. nav.barTintColor = [NCBrandColor sharedInstance].brand;
  622. nav.tintColor = [NCBrandColor sharedInstance].brandText;
  623. [nav setTitleTextAttributes:@{NSForegroundColorAttributeName : [NCBrandColor sharedInstance].brandText}];
  624. // Change bar bottom line shadow
  625. nav.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  626. if (!online)
  627. [nav setTitleTextAttributes:@{NSForegroundColorAttributeName : [NCBrandColor sharedInstance].connectionNo}];
  628. nav.hidden = hidden;
  629. [nav setAlpha:1];
  630. }
  631. - (void)aspectTabBar:(UITabBar *)tab hidden:(BOOL)hidden
  632. {
  633. tab.translucent = NO;
  634. tab.barTintColor = [NCBrandColor sharedInstance].tabBar;
  635. tab.tintColor = [NCBrandColor sharedInstance].brandElement;
  636. tab.hidden = hidden;
  637. [tab setAlpha:1];
  638. }
  639. - (void)plusButtonVisibile:(BOOL)visible
  640. {
  641. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  642. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  643. UIButton *buttonPlus = [tabBarController.view viewWithTag:99];
  644. UIImage *buttonImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarPlus"] multiplier:3 color:[NCBrandColor sharedInstance].brandElement];
  645. [buttonPlus setBackgroundImage:buttonImage forState:UIControlStateNormal];
  646. [buttonPlus setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  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. // Test Maintenance
  658. if (self.maintenanceMode)
  659. return;
  660. UIView *view = [[(UIButton *)sender superview] superview];
  661. CreateMenuAdd *menuAdd = [[CreateMenuAdd alloc] initWithThemingColor:[NCBrandColor sharedInstance].brandElement];
  662. [menuAdd createMenuWithView:view];
  663. }
  664. - (void)selectedTabBarController:(NSInteger)index
  665. {
  666. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  667. if (splitViewController.isCollapsed) {
  668. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  669. for (UINavigationController *nvc in tbc.viewControllers) {
  670. if ([nvc.topViewController isKindOfClass:[CCDetail class]])
  671. [nvc popToRootViewControllerAnimated:NO];
  672. }
  673. [tbc setSelectedIndex: index];
  674. } else {
  675. UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
  676. [nvcDetail popToRootViewControllerAnimated:NO];
  677. UITabBarController *tbc = splitViewController.viewControllers.firstObject;
  678. [tbc setSelectedIndex: index];
  679. }
  680. }
  681. - (NSString *)getTabBarControllerActiveServerUrl
  682. {
  683. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  684. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  685. NSString *serverUrl = [CCUtility getHomeServerUrlActiveUrl:self.activeUrl];
  686. NSInteger index = tabBarController.selectedIndex;
  687. // select active serverUrl
  688. if (index == k_tabBarApplicationIndexFile) {
  689. serverUrl = self.activeMain.serverUrl;
  690. } else if (index == k_tabBarApplicationIndexFavorite) {
  691. if (self.activeFavorites.serverUrl)
  692. serverUrl = self.activeFavorites.serverUrl;
  693. } else if (index == k_tabBarApplicationIndexPhotos) {
  694. serverUrl = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:self.activeUrl];
  695. }
  696. return serverUrl;
  697. }
  698. #pragma --------------------------------------------------------------------------------------------
  699. #pragma mark ===== Theming Color =====
  700. #pragma --------------------------------------------------------------------------------------------
  701. - (void)settingThemingColorBrand
  702. {
  703. if (self.activeAccount.length == 0 || self.maintenanceMode)
  704. return;
  705. if ([NCBrandOptions sharedInstance].use_themingColor) {
  706. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];
  707. [CCGraphics settingThemingColor:capabilities.themingColor themingColorElement:capabilities.themingColorElement themingColorText:capabilities.themingColorText];
  708. } else {
  709. [NCBrandColor sharedInstance].brand = [NCBrandColor sharedInstance].customer;
  710. [NCBrandColor sharedInstance].brandElement = [NCBrandColor sharedInstance].customer;
  711. [NCBrandColor sharedInstance].brandText = [NCBrandColor sharedInstance].customerText;
  712. }
  713. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeTheming" object:nil];
  714. }
  715. - (void)changeTheming:(UIViewController *)vc
  716. {
  717. // Change Navigation & TabBar color
  718. vc.navigationController.navigationBar.barTintColor = [NCBrandColor sharedInstance].brand;
  719. vc.tabBarController.tabBar.tintColor = [NCBrandColor sharedInstance].brandElement;
  720. // Change bar bottom line shadow
  721. vc.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  722. // Change button Plus
  723. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  724. UITabBarController *tabBarController = [splitViewController.viewControllers firstObject];
  725. UIButton *button = [tabBarController.view viewWithTag:99];
  726. UIImage *buttonImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarPlus"] multiplier:3 color:[NCBrandColor sharedInstance].brandElement];
  727. [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
  728. [button setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  729. // Tint Color GLOBAL WINDOW
  730. [self.window setTintColor:[NCBrandColor sharedInstance].textView];
  731. }
  732. #pragma --------------------------------------------------------------------------------------------
  733. #pragma mark ===== Manager Passcode =====
  734. #pragma --------------------------------------------------------------------------------------------
  735. - (BOOL)lockScreenManagerShouldShowLockScreen:(BKPasscodeLockScreenManager *)aManager
  736. {
  737. // ServerUrl active
  738. NSString *serverUrl = self.activeMain.serverUrl;
  739. BOOL isBlockZone = false;
  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 (serverUrl && _activeUrl) {
  748. while (![serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:_activeUrl]]) {
  749. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", self.activeAccount, serverUrl]];
  750. if (directory.lock) {
  751. isBlockZone = true;
  752. break;
  753. } else {
  754. serverUrl = [CCUtility deletingLastPathComponentFromServerUrl:serverUrl];
  755. if (serverUrl == self.activeUrl)
  756. break;
  757. }
  758. }
  759. }
  760. if ([CCUtility getOnlyLockDir] && !isBlockZone) return NO;
  761. return YES;
  762. }
  763. - (UIViewController *)lockScreenManagerPasscodeViewController:(BKPasscodeLockScreenManager *)aManager
  764. {
  765. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  766. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  767. viewController.delegate = self;
  768. viewController.title = [NCBrandOptions sharedInstance].brand;
  769. viewController.fromType = CCBKPasscodeFromLockScreen;
  770. viewController.inputViewTitlePassword = YES;
  771. if ([CCUtility getSimplyBlockCode]) {
  772. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  773. viewController.passcodeInputView.maximumLength = 6;
  774. } else {
  775. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  776. viewController.passcodeInputView.maximumLength = 64;
  777. }
  778. viewController.touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName: k_serviceShareKeyChain];
  779. viewController.touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  780. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  781. return navigationController;
  782. }
  783. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  784. {
  785. [aViewController dismissViewControllerAnimated:YES completion:nil];
  786. // is a lock screen
  787. if (aViewController.fromType == CCBKPasscodeFromLockScreen) {
  788. [aViewController dismissViewControllerAnimated:YES completion:nil];
  789. // start session Passcode Lock
  790. BOOL isBlockZone = false;
  791. NSString *serverUrl = self.activeMain.serverUrl;
  792. while (![serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:_activeUrl]]) {
  793. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", self.activeAccount, serverUrl]];
  794. if (directory.lock) {
  795. isBlockZone = true;
  796. break;
  797. } else {
  798. serverUrl = [CCUtility deletingLastPathComponentFromServerUrl:serverUrl];
  799. if (serverUrl == self.activeUrl)
  800. break;
  801. }
  802. }
  803. if (isBlockZone)
  804. self.sessionePasscodeLock = [NSDate date];
  805. }
  806. }
  807. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  808. {
  809. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromInit) {
  810. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  811. //self.lockUntilDate = nil;
  812. //self.failedAttempts = 0;
  813. aResultHandler(YES);
  814. } else aResultHandler(NO);
  815. } else aResultHandler(YES);
  816. }
  817. #pragma --------------------------------------------------------------------------------------------
  818. #pragma mark ===== reachabilityChanged =====
  819. #pragma --------------------------------------------------------------------------------------------
  820. -(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
  821. {
  822. if ([self.reachability isReachable]) {
  823. if (self.lastReachability == NO) {
  824. NSLog(@"[LOG] Request Service Server Nextcloud");
  825. [[NCService sharedInstance] startRequestServicesServer];
  826. }
  827. NSLog(@"[LOG] Reachability Changed: Reachable");
  828. self.lastReachability = YES;
  829. } else {
  830. if (self.lastReachability == YES) {
  831. [self messageNotification:@"_network_not_available_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:kCFURLErrorNotConnectedToInternet];
  832. }
  833. NSLog(@"[LOG] Reachability Changed: NOT Reachable");
  834. self.lastReachability = NO;
  835. }
  836. if ([self.reachability isReachableViaWiFi]) NSLog(@"[LOG] Reachability Changed: WiFi");
  837. if ([self.reachability isReachableViaWWAN]) NSLog(@"[LOG] Reachability Changed: WWAn");
  838. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"setTitleMain" object:nil];
  839. }
  840. #pragma --------------------------------------------------------------------------------------------
  841. #pragma mark ===== Fetch =====
  842. #pragma --------------------------------------------------------------------------------------------
  843. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  844. {
  845. NSLog(@"[LOG] Start perform Fetch With Completion Handler");
  846. // Verify new photo
  847. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  848. // after 20 sec
  849. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  850. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session != ''", self.activeAccount] sorted:nil ascending:NO];
  851. if ([records count] > 0) {
  852. completionHandler(UIBackgroundFetchResultNewData);
  853. } else {
  854. completionHandler(UIBackgroundFetchResultNoData);
  855. }
  856. NSLog(@"[LOG] End 20 sec. perform Fetch With Completion Handler");
  857. });
  858. }
  859. #pragma --------------------------------------------------------------------------------------------
  860. #pragma mark ===== Operation Networking & Session =====
  861. #pragma --------------------------------------------------------------------------------------------
  862. //
  863. // Method called by the system when all the background task has end
  864. //
  865. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
  866. {
  867. NSLog(@"[LOG] Start handle Events For Background URLSession: %@", identifier);
  868. // after 20 sec
  869. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  870. self.backgroundSessionCompletionHandler = completionHandler;
  871. void (^completionHandler)() = self.backgroundSessionCompletionHandler;
  872. self.backgroundSessionCompletionHandler = nil;
  873. completionHandler();
  874. NSLog(@"[LOG] End 20 sec. Start handle Events For Background URLSession: %@", identifier);
  875. });
  876. }
  877. - (void)addNetworkingOperationQueue:(NSOperationQueue *)netQueue delegate:(id)delegate metadataNet:(CCMetadataNet *)metadataNet
  878. {
  879. id operation;
  880. operation = [[OCnetworking alloc] initWithDelegate:delegate metadataNet:metadataNet withUser:_activeUser withUserID:_activeUserID withPassword:_activePassword withUrl:_activeUrl];
  881. [operation setQueuePriority:metadataNet.priority];
  882. [netQueue addOperation:operation];
  883. }
  884. #pragma --------------------------------------------------------------------------------------------
  885. #pragma mark ===== Process Load Download/Upload < k_timerProcess seconds > =====
  886. #pragma --------------------------------------------------------------------------------------------
  887. - (void)loadAutoDownloadUpload
  888. {
  889. tableMetadata *metadataForUpload, *metadataForDownload;
  890. long counterDownload = 0, counterUpload = 0;
  891. NSUInteger sizeDownload = 0, sizeUpload = 0;
  892. // Test Maintenance
  893. if (self.maintenanceMode)
  894. return;
  895. // E2EE : not in background
  896. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
  897. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d)", self.activeAccount, k_metadataStatusInUpload, k_metadataStatusUploading]];
  898. if (metadata) {
  899. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND e2eEncrypted == 1", metadata.directoryID]];
  900. if (directory != nil)
  901. return;
  902. }
  903. }
  904. // Stop Timer
  905. [_timerProcessAutoDownloadUpload invalidate];
  906. NSArray *metadatasDownload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d)", self.activeAccount, k_metadataStatusInDownload, k_metadataStatusDownloading] sorted:nil ascending:true];
  907. NSArray *metadatasUpload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d)", self.activeAccount, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:nil ascending:true];
  908. // Counter
  909. counterDownload = [metadatasDownload count];
  910. counterUpload = [metadatasUpload count];
  911. // Size
  912. for (tableMetadata *metadata in metadatasDownload) {
  913. sizeDownload = sizeDownload + metadata.size;
  914. }
  915. for (tableMetadata *metadata in metadatasUpload) {
  916. sizeUpload = sizeUpload + metadata.size;
  917. }
  918. NSLog(@"%@", [NSString stringWithFormat:@"[LOG] -PROCESS-AUTO-UPLOAD- | Download %ld - %@ | Upload %ld - %@", counterDownload, [CCUtility transformedSize:sizeDownload], counterUpload, [CCUtility transformedSize:sizeUpload]]);
  919. // ------------------------- <selector Download> -------------------------
  920. while (counterDownload < k_maxConcurrentOperationDownload) {
  921. metadataForDownload = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND status == %d", _activeAccount, k_metadataStatusWaitDownload]];
  922. if (metadataForDownload) {
  923. metadataForDownload.status = k_metadataStatusInDownload;
  924. tableMetadata *metadata = [[NCManageDatabase sharedInstance] addMetadata:metadataForDownload];
  925. [[CCNetworking sharedNetworking] downloadFile:metadata taskStatus:k_taskStatusResume delegate:_activeMain];
  926. counterDownload++;
  927. sizeDownload = sizeDownload + metadata.size;
  928. } else {
  929. break;
  930. }
  931. }
  932. // ------------------------- <selector Upload> -------------------------
  933. while (counterUpload < k_maxConcurrentOperationUpload) {
  934. if (sizeUpload > k_maxSizeOperationUpload) {
  935. break;
  936. }
  937. metadataForUpload = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND sessionSelector == %@ AND status == %d", _activeAccount, selectorUploadFile, k_metadataStatusWaitUpload]];
  938. if (metadataForUpload) {
  939. if ([metadataForUpload.session isEqualToString:k_upload_session_extension]) {
  940. metadataForUpload.session = k_upload_session;
  941. }
  942. metadataForUpload.status = k_metadataStatusInUpload;
  943. tableMetadata *metadata = [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  944. [[CCNetworking sharedNetworking] uploadFile:metadata taskStatus:k_taskStatusResume delegate:_activeMain];
  945. counterUpload++;
  946. sizeUpload = sizeUpload + metadata.size;
  947. } else {
  948. break;
  949. }
  950. }
  951. // ------------------------- <selector Auto Upload> -------------------------
  952. while (counterUpload < k_maxConcurrentOperationUpload) {
  953. if (sizeUpload > k_maxSizeOperationUpload) {
  954. break;
  955. }
  956. metadataForUpload = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND sessionSelector == %@ AND status == %d", _activeAccount, selectorUploadAutoUpload, k_metadataStatusWaitUpload]];
  957. if (metadataForUpload) {
  958. metadataForUpload.status = k_metadataStatusInUpload;
  959. tableMetadata *metadata = [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  960. [[CCNetworking sharedNetworking] uploadFile:metadata taskStatus:k_taskStatusResume delegate:_activeMain];
  961. counterUpload++;
  962. sizeUpload = sizeUpload + metadata.size;
  963. } else {
  964. break;
  965. }
  966. }
  967. // ------------------------- <selector Auto Upload All> ----------------------
  968. // Verify num error k_maxErrorAutoUploadAll after STOP (100)
  969. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND sessionSelector == %@ AND status == %i", _activeAccount, selectorUploadAutoUploadAll, k_metadataStatusUploadError] sorted:nil ascending:NO];
  970. NSInteger errorCount = [metadatas count];
  971. if (errorCount >= k_maxErrorAutoUploadAll) {
  972. [self messageNotification:@"_error_" description:@"_too_errors_automatic_all_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  973. [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionAutoUpload selector:selectorUploadAutoUploadAll note:@"_too_errors_automatic_all_" type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
  974. } else {
  975. while (counterUpload < k_maxConcurrentOperationUpload) {
  976. if (sizeUpload > k_maxSizeOperationUpload) {
  977. break;
  978. }
  979. metadataForUpload = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND sessionSelector == %@ AND status == %d", _activeAccount, selectorUploadAutoUploadAll, k_metadataStatusWaitUpload]];
  980. if (metadataForUpload) {
  981. metadataForUpload.status = k_metadataStatusInUpload;
  982. tableMetadata *metadata = [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  983. [[CCNetworking sharedNetworking] uploadFile:metadata taskStatus:k_taskStatusResume delegate:_activeMain];
  984. counterUpload++;
  985. sizeUpload = sizeUpload + metadata.size;
  986. } else {
  987. break;
  988. }
  989. }
  990. }
  991. // ------------------------- < END > ----------------------
  992. // No Download/upload available ? --> remove errors for retry
  993. //
  994. if (counterDownload+counterUpload == 0) {
  995. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d)", _activeAccount, k_metadataStatusDownloadError, k_metadataStatusUploadError] sorted:nil ascending:NO];
  996. for (tableMetadata *metadata in metadatas) {
  997. if (metadata.status == k_metadataStatusDownloadError)
  998. metadata.status = k_metadataStatusWaitDownload;
  999. else if (metadata.status == k_metadataStatusUploadError)
  1000. metadata.status = k_metadataStatusWaitUpload;
  1001. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1002. }
  1003. }
  1004. // Start Timer
  1005. _timerProcessAutoDownloadUpload = [NSTimer scheduledTimerWithTimeInterval:k_timerProcessAutoDownloadUpload target:self selector:@selector(loadAutoDownloadUpload) userInfo:nil repeats:YES];
  1006. }
  1007. #pragma --------------------------------------------------------------------------------------------
  1008. #pragma mark ===== Verify internal error in Download/Upload =====
  1009. #pragma --------------------------------------------------------------------------------------------
  1010. - (void)verifyInternalErrorDownloadingUploading
  1011. {
  1012. // Test Maintenance
  1013. if (self.maintenanceMode || self.activeAccount.length == 0)
  1014. return;
  1015. NSArray *recordsInDownloading = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session != %@ AND status == %d", self.activeAccount, k_download_session_extension, k_metadataStatusDownloading] sorted:nil ascending:true];
  1016. for (tableMetadata *metadata in recordsInDownloading) {
  1017. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1018. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1019. NSURLSessionTask *findTask;
  1020. for (NSURLSessionTask *task in downloadTasks) {
  1021. if (task.taskIdentifier == metadata.sessionTaskIdentifier) {
  1022. findTask = task;
  1023. }
  1024. }
  1025. if (!findTask) {
  1026. metadata.sessionTaskIdentifier = k_taskIdentifierDone;
  1027. metadata.status = k_metadataStatusWaitDownload;
  1028. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1029. }
  1030. }];
  1031. }
  1032. NSArray *recordsInUploading = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session != %@ AND status == %d", self.activeAccount, k_upload_session_extension, k_metadataStatusUploading] sorted:nil ascending:true];
  1033. for (tableMetadata *metadata in recordsInUploading) {
  1034. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1035. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1036. NSURLSessionTask *findTask;
  1037. for (NSURLSessionTask *task in uploadTasks) {
  1038. if (task.taskIdentifier == metadata.sessionTaskIdentifier) {
  1039. findTask = task;
  1040. }
  1041. }
  1042. if (!findTask) {
  1043. metadata.sessionTaskIdentifier = k_taskIdentifierDone;
  1044. metadata.status = k_metadataStatusWaitUpload;
  1045. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1046. }
  1047. }];
  1048. }
  1049. }
  1050. #pragma --------------------------------------------------------------------------------------------
  1051. #pragma mark ===== Open CCUploadFromOtherUpp =====
  1052. #pragma --------------------------------------------------------------------------------------------
  1053. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  1054. {
  1055. return YES;
  1056. }
  1057. // Method called from iOS system to send a file from other app.
  1058. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
  1059. {
  1060. NSError *error;
  1061. NSLog(@"[LOG] the path is: %@", url.path);
  1062. NSArray *splitedUrl = [url.path componentsSeparatedByString:@"/"];
  1063. self.fileNameUpload = [NSString stringWithFormat:@"%@",[splitedUrl objectAtIndex:([splitedUrl count]-1)]];
  1064. if (self.activeAccount) {
  1065. [[NSFileManager defaultManager]removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:nil];
  1066. [[NSFileManager defaultManager]moveItemAtPath:url.path toPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:&error];
  1067. if (error == nil) {
  1068. UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
  1069. UINavigationController *splitNavigationController = [splitViewController.viewControllers firstObject];
  1070. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
  1071. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1072. [splitNavigationController presentViewController:navigationController animated:YES completion:nil];
  1073. });
  1074. }
  1075. }
  1076. return YES;
  1077. }
  1078. #pragma --------------------------------------------------------------------------------------------
  1079. #pragma mark ===== Crashlytics =====
  1080. #pragma --------------------------------------------------------------------------------------------
  1081. - (void) logUser
  1082. {
  1083. if (self.activeAccount.length > 0)
  1084. [CrashlyticsKit setUserName:self.activeAccount];
  1085. }
  1086. #pragma --------------------------------------------------------------------------------------------
  1087. #pragma mark ===== Maintenance Mode =====
  1088. #pragma --------------------------------------------------------------------------------------------
  1089. - (void)maintenanceMode:(BOOL)mode
  1090. {
  1091. self.maintenanceMode = mode;
  1092. }
  1093. #pragma --------------------------------------------------------------------------------------------
  1094. #pragma mark ===== UPGRADE =====
  1095. #pragma --------------------------------------------------------------------------------------------
  1096. - (BOOL)upgrade
  1097. {
  1098. #ifdef DEBUG
  1099. //self.maintenanceMode = YES;
  1100. #endif
  1101. NSString *actualVersion = [CCUtility getVersion];
  1102. NSString *actualBuild = [CCUtility getBuild];
  1103. /* ---------------------- UPGRADE VERSION ----------------------- */
  1104. // VERSION < 2.17.6
  1105. if (([actualVersion compare:@"2.17.6" options:NSNumericSearch] == NSOrderedAscending)) {
  1106. // Remove All old Photo Library
  1107. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:nil];
  1108. }
  1109. // VERSION == 2.17.6
  1110. if ([actualVersion isEqualToString:@"2.17.6"]) {
  1111. // Build < 10
  1112. if (([actualBuild compare:@"10" options:NSNumericSearch] == NSOrderedAscending) || actualBuild == nil) {
  1113. // Remove All old Photo Library
  1114. //[[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:nil];
  1115. }
  1116. }
  1117. if (([actualVersion compare:@"2.19.1" options:NSNumericSearch] == NSOrderedAscending)) {
  1118. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:nil];
  1119. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  1120. }
  1121. if (([actualVersion compare:@"2.22.0" options:NSNumericSearch] == NSOrderedAscending)) {
  1122. NSArray *records = [[NCManageDatabase sharedInstance] getTableLocalFilesWithPredicate:[NSPredicate predicateWithFormat:@"#size > 0"] sorted:@"account" ascending:NO];
  1123. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  1124. NSString *account = @"";
  1125. NSString *directoryUser = @"";
  1126. NSString *fileName, *fileNameIco;
  1127. for (tableLocalFile *record in records) {
  1128. if (![account isEqualToString:record.account]) {
  1129. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", record.account]];
  1130. if (tableAccount) {
  1131. directoryUser = [CCUtility getDirectoryActiveUser:tableAccount.user activeUrl:tableAccount.url];
  1132. account = record.account;
  1133. }
  1134. }
  1135. fileName = [NSString stringWithFormat:@"%@/%@", directoryUser, record.fileID];
  1136. fileNameIco = [NSString stringWithFormat:@"%@/%@.ico", directoryUser, record.fileID];
  1137. if (![directoryUser isEqualToString:@""] && [[NSFileManager defaultManager] fileExistsAtPath:fileName]) {
  1138. [CCUtility moveFileAtPath:fileName toPath:[CCUtility getDirectoryProviderStorageFileID:record.fileID fileName:record.fileName]];
  1139. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameIco])
  1140. [CCUtility moveFileAtPath:fileNameIco toPath:[CCUtility getDirectoryProviderStorageIconFileID:record.fileID fileNameView:record.fileName]];
  1141. }
  1142. }
  1143. });
  1144. }
  1145. return YES;
  1146. }
  1147. @end