Browse Source

Add checkServerSync

Marino Faggiana 8 years ago
parent
commit
8d3eeafe44
2 changed files with 30 additions and 0 deletions
  1. 1 0
      iOSClient/Networking/OCNetworking.h
  2. 29 0
      iOSClient/Networking/OCNetworking.m

+ 1 - 0
iOSClient/Networking/OCNetworking.h

@@ -48,6 +48,7 @@
 
 - (NSError *)createFolderSync:(NSString *)folderPathName;
 - (NSError *)readFileSync:(NSString *)filePathName;
+- (NSError *)checkServerSync:(NSString *)serverUrl;
 
 @end
 

+ 29 - 0
iOSClient/Networking/OCNetworking.m

@@ -890,6 +890,35 @@
 #pragma mark =====  Server =====
 #pragma --------------------------------------------------------------------------------------------
 
+- (NSError *)checkServerSync:(NSString *)serverUrl
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    __block NSError *returnError;
+    
+    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+        
+        returnError = nil;
+        dispatch_semaphore_signal(semaphore);
+
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        returnError = error;
+        dispatch_semaphore_signal(semaphore);
+    }];
+     
+    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
+    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
+     
+    return returnError;
+}
+
 - (void)getFeaturesSupportedByServer
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;