Browse Source

Listen for nextcloud:// urls.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
Ivan Sein 6 years ago
parent
commit
3ce345aaa2
2 changed files with 53 additions and 0 deletions
  1. 40 0
      iOSClient/AppDelegate.m
  2. 13 0
      iOSClient/Brand/iOSClient.plist

+ 40 - 0
iOSClient/AppDelegate.m

@@ -1483,6 +1483,46 @@ PKPushRegistry *pushRegistry;
 // Method called from iOS system to send a file from other app.
 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
 {
+    NSString *scheme = url.scheme;
+    if ([scheme isEqualToString:@"nextcloud"]) {
+        NSString *action = url.host;
+        if ([action isEqualToString:@"open-file"]) {
+            NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
+            NSArray *queryItems = urlComponents.queryItems;
+            NSString *user = [self valueForKey:@"user" fromQueryItems:queryItems];
+            NSString *fileURLString = [self valueForKey:@"url" fromQueryItems:queryItems];
+            NSURL *fileURL = [NSURL URLWithString:fileURLString];
+            
+            tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
+            if (activeAccount) {
+                NSURL *activeAccountURL = [NSURL URLWithString:activeAccount.url];
+                NSString *activeAccountUser = activeAccount.user;
+                if ([activeAccountURL.host isEqualToString:fileURL.host] && [user isEqualToString:activeAccountUser]) {
+                    // Open the file
+                } else {
+                    tableAccount *matchedAccount = nil;
+                    NSArray *accounts = [[NCManageDatabase sharedInstance] getAccounts];
+                    for (tableAccount *account in accounts) {
+                        NSURL *accountURL = [NSURL URLWithString:account.url];
+                        NSString *accountUser = account.user;
+                        if ([accountURL.host isEqualToString:fileURL.host] && [user isEqualToString:accountUser]) {
+                            matchedAccount = account;
+                        }
+                    }
+                    if (matchedAccount) {
+                        // Change account and open the file
+                    } else {
+                        // Show add account dialog
+                    }
+                }
+            } else {
+                // Show add account dialog
+            }
+        }
+        
+        return YES;
+    }
+    
     NSError *error;
     NSLog(@"[LOG] the path is: %@", url.path);
         

+ 13 - 0
iOSClient/Brand/iOSClient.plist

@@ -49,6 +49,19 @@
 	<string>2.23.4</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
+	<key>CFBundleURLTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeRole</key>
+			<string>Editor</string>
+			<key>CFBundleURLName</key>
+			<string>it.twsweb.Nextcloud</string>
+			<key>CFBundleURLSchemes</key>
+			<array>
+				<string>nextcloud</string>
+			</array>
+		</dict>
+	</array>
 	<key>CFBundleVersion</key>
 	<string>8</string>
 	<key>FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED</key>