marinofaggiana 6 年之前
父节点
当前提交
10451c71ec

+ 2 - 2
iOSClient/AppDelegate.h

@@ -160,8 +160,8 @@
 - (NSString *)getTabBarControllerActiveServerUrl;
 
 // Push Notification
-- (void)subscribingNextcloudServerPushNotification;
-- (void)unsubscribingNextcloudServerPushNotification;
+- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url;
+- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account;
 
 // Theming Color
 - (void)settingThemingColorBrand;

+ 18 - 9
iOSClient/AppDelegate.m

@@ -396,26 +396,26 @@
 #pragma mark ===== Push Notification =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)subscribingNextcloudServerPushNotification
+- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url
 {
     // test
     if (self.activeAccount.length == 0 || self.maintenanceMode)
         return;
     
-    [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair:self.activeAccount];
+    [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair:account];
 
     NSString *pushToken = [CCUtility getPushNotificationToken];
     NSString *pushTokenHash = [[NCEndToEndEncryption sharedManager] createSHA512:pushToken];
-    NSData *ncPNPublicKey = [CCUtility getPushNotificationPublicKey:self.activeAccount];
+    NSData *ncPNPublicKey = [CCUtility getPushNotificationPublicKey:account];
     NSString *devicePublicKey = [[NSString alloc] initWithData:ncPNPublicKey encoding:NSUTF8StringEncoding];
     
     self.pnDeviceIdentifier = nil;
     self.pnDeviceIdentifierSignature = nil;
     self.pnPublicKey = nil;
 
-    [[OCNetworking sharedManager] subscribingPushNotificationWithAccount:self.activeAccount url:self.activeUrl pushToken:pushToken Hash:pushTokenHash devicePublicKey:devicePublicKey completion:^(NSString *account, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode) {
+    [[OCNetworking sharedManager] subscribingPushNotificationWithAccount:account url:url pushToken:pushToken Hash:pushTokenHash devicePublicKey:devicePublicKey completion:^(NSString *accountCompletion, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode) {
         
-        if (errorCode == 0 && [account isEqualToString:self.activeAccount]) {
+        if (errorCode == 0 && [accountCompletion isEqualToString:account]) {
             NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
             self.pnDeviceIdentifier = deviceIdentifier;
             self.pnDeviceIdentifierSignature = deviceIdentifierSignature;
@@ -428,13 +428,13 @@
     }];
 }
 
-- (void)unsubscribingNextcloudServerPushNotification
+- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account
 {
     // test
     if (self.activeAccount.length == 0 || self.maintenanceMode)
         return;
     
-    [[OCNetworking sharedManager] unsubscribingPushNotificationWithAccount:self.activeAccount url:self.activeUrl deviceIdentifier:self.pnDeviceIdentifier deviceIdentifierSignature:self.pnDeviceIdentifierSignature publicKey:self.pnPublicKey completion:^(NSString *account, NSString *message, NSInteger errorCode) {
+    [[OCNetworking sharedManager] unsubscribingPushNotificationWithAccount:account url:self.activeUrl deviceIdentifier:self.pnDeviceIdentifier deviceIdentifierSignature:self.pnDeviceIdentifierSignature publicKey:self.pnPublicKey completion:^(NSString *account, NSString *message, NSInteger errorCode) {
        
         if (errorCode == 0) {
             NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
@@ -532,9 +532,18 @@
         return;
     
     NSLog(@"FCM registration token: %@", fcmToken);
-    [CCUtility setPushNotificationToken:fcmToken];
     
-    [self subscribingNextcloudServerPushNotification];
+    NSString *token = [CCUtility getPushNotificationToken];
+    if (![token isEqualToString:fcmToken]) {
+        
+        // da fare per tutti gli utenti
+        
+        
+        
+        [CCUtility setPushNotificationToken:fcmToken];
+    }
+
+    //[self subscribingNextcloudServerPushNotification];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 1
iOSClient/Login/CCLogin.m

@@ -360,7 +360,7 @@
                     [CCUtility setIntro:YES];
                     
                     // LOGOUT
-                    [appDelegate unsubscribingNextcloudServerPushNotification];
+                    //[appDelegate unsubscribingNextcloudServerPushNotification];
                     
                     [[NCManageDatabase sharedInstance] deleteAccount:account];
                     [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];

+ 1 - 1
iOSClient/Login/CCLoginWeb.swift

@@ -125,7 +125,7 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                         CCUtility.setIntro(true)
                         
                         // LOGOUT
-                        appDelegate.unsubscribingNextcloudServerPushNotification()
+                        //appDelegate.unsubscribingNextcloudServerPushNotification()
                         
                         // Add new account
                         NCManageDatabase.sharedInstance.deleteAccount(account)

+ 2 - 8
iOSClient/Main/CCMain.m

@@ -915,9 +915,7 @@
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
         // go to home sweet home
         [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-    });
-    
-    [appDelegate subscribingNextcloudServerPushNotification];
+    });    
 }
 
 #pragma mark -
@@ -2287,9 +2285,7 @@
 - (void)changeDefaultAccount:(CCMenuItem *)sender
 {
     // LOGOUT
-        
-    [appDelegate unsubscribingNextcloudServerPushNotification];
-        
+    
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
     if (tableAccount) {
             
@@ -2299,8 +2295,6 @@
     
         // go to home sweet home
         [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-            
-        [appDelegate subscribingNextcloudServerPushNotification];
     }
 }
 

+ 1 - 3
iOSClient/Main/CCMore.swift

@@ -474,9 +474,7 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
         
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "initializeMain"), object: nil, userInfo: nil)
         
-        appDelegate.selectedTabBarController(Int(k_tabBarApplicationIndexFile))
-        
-        appDelegate.subscribingNextcloudServerPushNotification()
+        appDelegate.selectedTabBarController(Int(k_tabBarApplicationIndexFile))        
     }
 }
 

+ 1 - 1
iOSClient/Main/CCSplit.m

@@ -181,7 +181,7 @@
 {
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
     
-    [appDelegate subscribingNextcloudServerPushNotification];
+    [appDelegate subscribingNextcloudServerPushNotification:appDelegate.activeAccount url:appDelegate.activeUrl];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 2 - 6
iOSClient/Settings/CCManageAccount.m

@@ -203,8 +203,6 @@
 - (void)loginSuccess:(NSInteger)loginType
 {
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-    
-    [appDelegate subscribingNextcloudServerPushNotification];
 }
 
 
@@ -236,7 +234,7 @@
 
 - (void)deleteAccount:(NSString *)account
 {
-    [appDelegate unsubscribingNextcloudServerPushNotification];
+    [appDelegate unsubscribingNextcloudServerPushNotification:account];
     
     [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
     [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
@@ -302,9 +300,7 @@
         // Init home
         [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
             
-        [self UpdateForm];
-            
-        [appDelegate subscribingNextcloudServerPushNotification];
+        [self UpdateForm];            
     }
 }