瀏覽代碼

Add url scheme for switching account

Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
Milen Pivchev 1 年之前
父節點
當前提交
f87cbf37c8
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. 18 0
      iOSClient/AppDelegate.swift

+ 18 - 0
iOSClient/AppDelegate.swift

@@ -931,6 +931,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 }
             }
             return true
+
+        /*
+         Example:
+         nextcloud://open-and-switch-account?user=marinofaggiana&url=https://cloud.nextcloud.com
+         */
+
+        } else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-and-switch-account" {
+            guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return false }
+            let queryItems = urlComponents.queryItems
+
+            guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
+            guard let urlScheme = CCUtility.value(forKey: "url", fromQueryItems: queryItems) else { return false }
+
+            if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
+                return false
+            }
+
+            return true
         } else {
             let applicationHandle = NCApplicationHandle()
             let isHandled = applicationHandle.applicationOpenURL(url)