Browse Source

fix nextcloud schema

marinofaggiana 6 years ago
parent
commit
3e2a8167dd
3 changed files with 17 additions and 8 deletions
  1. 8 7
      iOSClient/AppDelegate.m
  2. 2 1
      iOSClient/Utility/CCUtility.h
  3. 7 0
      iOSClient/Utility/CCUtility.m

+ 8 - 7
iOSClient/AppDelegate.m

@@ -1495,20 +1495,23 @@ PKPushRegistry *pushRegistry;
 // Method called from iOS system to send a file from other app.
 // Method called from iOS system to send a file from other app.
 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
 {
 {
+    if (self.activeAccount.length == 0 || self.maintenanceMode)
+        return YES;
+    
     NSString *scheme = url.scheme;
     NSString *scheme = url.scheme;
     if ([scheme isEqualToString:@"nextcloud"]) {
     if ([scheme isEqualToString:@"nextcloud"]) {
         NSString *action = url.host;
         NSString *action = url.host;
         if ([action isEqualToString:@"open-file"]) {
         if ([action isEqualToString:@"open-file"]) {
             NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
             NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
             NSArray *queryItems = urlComponents.queryItems;
             NSArray *queryItems = urlComponents.queryItems;
-            NSString *user = [self valueForKey:@"user" fromQueryItems:queryItems];
-            NSString *fileURLString = [self valueForKey:@"url" fromQueryItems:queryItems];
+            NSString *user = [CCUtility valueForKey:@"user" fromQueryItems:queryItems];
+            NSString *fileURLString = [CCUtility valueForKey:@"url" fromQueryItems:queryItems];
             NSURL *fileURL = [NSURL URLWithString:fileURLString];
             NSURL *fileURL = [NSURL URLWithString:fileURLString];
             
             
             tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
             tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
-            if (activeAccount) {
-                NSURL *activeAccountURL = [NSURL URLWithString:activeAccount.url];
-                NSString *activeAccountUser = activeAccount.user;
+            if (account) {
+                NSURL *activeAccountURL = [NSURL URLWithString:account.url];
+                NSString *activeAccountUser = account.user;
                 if ([activeAccountURL.host isEqualToString:fileURL.host] && [user isEqualToString:activeAccountUser]) {
                 if ([activeAccountURL.host isEqualToString:fileURL.host] && [user isEqualToString:activeAccountUser]) {
                     // Open the file
                     // Open the file
                 } else {
                 } else {
@@ -1527,8 +1530,6 @@ PKPushRegistry *pushRegistry;
                         // Show add account dialog
                         // Show add account dialog
                     }
                     }
                 }
                 }
-            } else {
-                // Show add account dialog
             }
             }
         }
         }
         
         

+ 2 - 1
iOSClient/Utility/CCUtility.h

@@ -247,6 +247,7 @@
 + (NSDate *)datetimeWithOutDate:(NSDate *)datDate;
 + (NSDate *)datetimeWithOutDate:(NSDate *)datDate;
 + (BOOL)isValidEmail:(NSString *)checkString;
 + (BOOL)isValidEmail:(NSString *)checkString;
 + (NSString *)URLEncodeStringFromString:(NSString *)string;
 + (NSString *)URLEncodeStringFromString:(NSString *)string;
-+ (NSString*)hexRepresentation:(NSData *)data spaces:(BOOL)spaces;
++ (NSString *)hexRepresentation:(NSData *)data spaces:(BOOL)spaces;
++ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems;
 
 
 @end
 @end

+ 7 - 0
iOSClient/Utility/CCUtility.m

@@ -1582,4 +1582,11 @@
     return hex;
     return hex;
 }
 }
 
 
++ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems
+{
+    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
+    NSURLQueryItem *queryItem = [[queryItems filteredArrayUsingPredicate:predicate] firstObject];
+    return queryItem.value;
+}
+
 @end
 @end