Browse Source

API Push notifications as a Nextcloud client device

Marino Faggiana 8 years ago
parent
commit
02589a3ed9
2 changed files with 12 additions and 5 deletions
  1. 11 4
      iOSClient/AppDelegate.m
  2. 1 1
      iOSClient/Networking/OCNetworking.m

+ 11 - 4
iOSClient/AppDelegate.m

@@ -429,13 +429,20 @@
     NSDictionary *keys = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:k_nextcloudDevicePushKey ofType:@"plist"]];
     
     NSString *devicePublicKey = [keys objectForKey:@"devicePublicKey"];
-    NSString *deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""];
-    NSLog(@"DEVICE TOKEN = %@", deviceTokenString);
-    NSLog(@"DEVICE PUBLIC KEY = %@", devicePublicKey);
+    NSString *pushTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""];
+    NSString *pushTokenHash = [[CCCrypto sharedManager] createSHA512:pushTokenString];
     
+    NSLog(@"DEVICE TOKEN = %@", pushTokenString);
+    NSLog(@"DEVICE PUBLIC KEY = %@", devicePublicKey);
     
-    if ([devicePublicKey length] > 0 && [deviceTokenString length] > 0) {
+    if ([devicePublicKey length] > 0 && [pushTokenHash length] > 0) {
+        
+        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+        NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:pushTokenHash,@"pushTokenHash", devicePublicKey, @"devicePublicKey", nil];
         
+        metadataNet.action = actionSubscribingNextcloudServer;
+        metadataNet.options = options;
+        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
     }
 }
 

+ 1 - 1
iOSClient/Networking/OCNetworking.m

@@ -1229,7 +1229,7 @@
     NSString *pushTokenHash = [parameter objectForKey:@"pushTokenHash"];
     NSString *devicePublicKey = [parameter objectForKey:@"devicePublicKey"];
     
-    [communication subscribingNextcloudServerPush:_metadataNet.serverUrl pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+    [communication subscribingNextcloudServerPush:[_activeUrl stringByAppendingString:@"/"] pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
         [self complete];