Browse Source

Add Timer for updateApplicationIconBadgeNumber

Marino Faggiana 8 years ago
parent
commit
23125af24c

+ 2 - 1
iOSClient/AppDelegate.h

@@ -45,6 +45,8 @@
 
 // Timer Process
 @property (nonatomic, strong) NSTimer *timerProcess;
+@property (nonatomic, strong) NSTimer *timerUpdateApplicationIconBadgeNumber;
+@property (nonatomic, strong) NSTimer *timerVerifySessionInProgress;
 
 // For LMMediaPlayerView
 @property (strong, nonatomic) UIWindow *window;
@@ -83,7 +85,6 @@
 @property (nonatomic, copy) void (^backgroundSessionCompletionHandler)(void);
 @property (nonatomic, strong) NSDate *sessionDateLastUploadTasks;
 @property (nonatomic, strong) NSDate *sessionDateLastDownloadTasks;
-@property (nonatomic, strong) NSTimer *timerVerifySessionInProgress;
 
 // Network Share
 @property (nonatomic, strong) NSMutableDictionary *sharesID;

+ 11 - 24
iOSClient/AppDelegate.m

@@ -190,7 +190,6 @@
     // Verify Session in progress and Init date task
     self.sessionDateLastDownloadTasks = [NSDate date];
     self.sessionDateLastUploadTasks = [NSDate date];
-    self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:k_timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
     
     // Background Fetch
     [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
@@ -271,9 +270,11 @@
             [self handleShortCutItem:shortcutItem];
     }
     
-    // Start timer Verify Process
+    // Start Timer
     self.timerProcess = [NSTimer scheduledTimerWithTimeInterval:k_timerProcess target:self selector:@selector(process) userInfo:nil repeats:YES];
-    
+    self.timerVerifySessionInProgress = [NSTimer scheduledTimerWithTimeInterval:k_timerVerifySession target:self selector:@selector(verifyDownloadUploadInProgress) userInfo:nil repeats:YES];
+    self.timerUpdateApplicationIconBadgeNumber = [NSTimer scheduledTimerWithTimeInterval:k_timerUpdateApplicationIconBadgeNumber target:self selector:@selector(updateApplicationIconBadgeNumber) userInfo:nil repeats:YES];
+
     // Registration Push Notification
     UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
     UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
@@ -909,29 +910,21 @@
     _queueNumUploadWWan = [[CCCoreData getTableMetadataUploadWWanAccount:self.activeAccount] count];
     
     // netQueueDownload
-    for (NSOperation *operation in [app.netQueueDownload operations]) {
-        
+    for (NSOperation *operation in [app.netQueueDownload operations])
         if (((OCnetworking *)operation).isExecuting == NO) _queueNunDownload++;
-    }
     
     // netQueueDownloadWWan
-    for (NSOperation *operation in [app.netQueueDownloadWWan operations]) {
-        
+    for (NSOperation *operation in [app.netQueueDownloadWWan operations])
         if (((OCnetworking *)operation).isExecuting == NO) _queueNumDownloadWWan++;
-    }
     
     // netQueueUpload
-    for (NSOperation *operation in [app.netQueueUpload operations]) {
-        
+    for (NSOperation *operation in [app.netQueueUpload operations])
         if (((OCnetworking *)operation).isExecuting == NO) _queueNumUpload++;
-    }
-    
+
     // netQueueUploadWWan
-    for (NSOperation *operation in [app.netQueueUploadWWan operations]) {
-        
+    for (NSOperation *operation in [app.netQueueUploadWWan operations])
         if (((OCnetworking *)operation).isExecuting == NO) _queueNumUploadWWan++;
-    }
-    
+
     // Total
     NSUInteger total = _queueNunDownload + _queueNumDownloadWWan + _queueNumUpload + _queueNumUploadWWan + [CCCoreData countTableAutomaticUploadForAccount:self.activeAccount selector:nil];
     
@@ -1180,8 +1173,6 @@
     [_netQueueDownloadWWan cancelAllOperations];
     [_netQueueUpload cancelAllOperations];
     [_netQueueUploadWWan cancelAllOperations];
-    
-    [self performSelector:@selector(updateApplicationIconBadgeNumber) withObject:nil afterDelay:0.5];
 }
 
 - (void)addNetworkingOperationQueue:(NSOperationQueue *)netQueue delegate:(id)delegate metadataNet:(CCMetadataNet *)metadataNet
@@ -1254,8 +1245,6 @@
             [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutomatic note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
             
             [CCCoreData deleteTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:metadataNet.assetLocalIdentifier];
-            
-            [self updateApplicationIconBadgeNumber];
         }
 
         metadataNet = [CCCoreData getTableAutomaticUploadForAccount:self.activeAccount selector:selectorUploadAutomatic];
@@ -1299,9 +1288,7 @@
             
             [CCCoreData addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selectorUploadAutomatic note:@"Internal error image/video not found [0]" type:k_activityTypeFailure verbose:k_activityVerboseHigh account:_activeAccount activeUrl:_activeUrl];
             
-            [CCCoreData deleteTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:metadataNet.assetLocalIdentifier];
-            
-            [self updateApplicationIconBadgeNumber];
+            [CCCoreData deleteTableAutomaticUploadForAccount:_activeAccount assetLocalIdentifier:metadataNet.assetLocalIdentifier];            
         }
     }
     

+ 1 - 0
iOSClient/CCGlobal.h

@@ -136,6 +136,7 @@ extern NSString *const urlBaseUploadDB;
 
 #define k_timerVerifySession                            15
 #define k_timerProcess                                  7
+#define k_timerUpdateApplicationIconBadgeNumber         2
 
 #define k_maxConcurrentOperation                        10
 #define k_maxConcurrentOperationDownloadUpload          10

+ 1 - 8
iOSClient/Favorites/CCFavorites.m

@@ -104,9 +104,6 @@
 - (void)viewDidAppear:(BOOL)animated
 {
     [super viewDidAppear:animated];
-        
-    // update Badge
-    [app updateApplicationIconBadgeNumber];
 }
 
 - (void)didReceiveMemoryWarning {
@@ -220,8 +217,6 @@
 - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
 {    
     [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
-    
-    [app updateApplicationIconBadgeNumber];
 }
 
 - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
@@ -240,9 +235,7 @@
         
         if ([self shouldPerformSegue])
             [self performSegueWithIdentifier:@"segueDetail" sender:self];
-    }
-    
-    [app updateApplicationIconBadgeNumber];
+    }    
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 4
iOSClient/Local storage/CCLocalStorage.m

@@ -80,10 +80,7 @@
 // E' arrivato
 - (void)viewDidAppear:(BOOL)animated
 {
-    [super viewDidAppear:animated];
-        
-    // update Badge
-    [app updateApplicationIconBadgeNumber];
+    [super viewDidAppear:animated];        
 }
 
 - (void)didReceiveMemoryWarning {

+ 1 - 5
iOSClient/Main/CCMain.m

@@ -4753,8 +4753,6 @@
     
         [self.tableView reloadEmptyDataSet];
         
-        [app updateApplicationIconBadgeNumber];
-        
         return;
     }
     
@@ -4805,9 +4803,7 @@
          NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
     }
     
-    [self tableViewReload];
-    
-    [app updateApplicationIconBadgeNumber];
+    [self tableViewReload];    
 }
 
 - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows

+ 8 - 6
iOSClient/Networking/CCNetworking.m

@@ -329,12 +329,6 @@
             [CCUtility removeAllFileID_UPLOAD_ActiveUser:activeUser activeUrl:activeUrl];
         });
     }
-
-#ifndef EXTENSION
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-        [app updateApplicationIconBadgeNumber];
-    });
-#endif
 }
 
 - (void)settingSession:(NSString *)sessionDescription sessionTaskIdentifier:(NSUInteger)sessionTaskIdentifier taskStatus:(NSInteger)taskStatus
@@ -600,6 +594,10 @@
         // Refresh datasource if is not a Plist
         if ([_delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)] && [CCUtility isCryptoPlistString:fileName] == NO)
             [_delegate reloadDatasource:serverUrl fileID:fileID selector:selector];
+        
+#ifndef EXTENSION
+        [app updateApplicationIconBadgeNumber];
+#endif
     });
 }
 
@@ -1283,6 +1281,10 @@
         // refresh main
         if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
             [self.delegate reloadDatasource:serverUrl fileID:nil selector:selector];
+        
+#ifndef EXTENSION
+        [app updateApplicationIconBadgeNumber];
+#endif
     });
 }
 

+ 0 - 5
iOSClient/Settings/CCManageCameraUpload.m

@@ -487,11 +487,6 @@
 - (void)dropAutomaticUploadWithSelector:(NSString *)selector
 {
     [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:selector];
-    
-    // Update icon badge number
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-        [app updateApplicationIconBadgeNumber];
-    });
 }
 
 @end

+ 1 - 6
iOSClient/Transfers/CCTransfers.m

@@ -95,9 +95,6 @@
     [super viewDidAppear:animated];
     
     [self reloadDatasource];
-    
-    // update Badge
-    [app updateApplicationIconBadgeNumber];
 }
 
 - (void)didReceiveMemoryWarning {
@@ -313,9 +310,7 @@
         
     _sectionDataSource  = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata groupByField:@"session" replaceDateToExifDate:NO activeAccount:app.activeAccount];
         
-    [_tableView reloadData];
-    
-    [app updateApplicationIconBadgeNumber];
+    [_tableView reloadData];    
 }
 
 #pragma --------------------------------------------------------------------------------------------