Selaa lähdekoodia

remove valueForKey:

Marino Faggiana 1 vuosi sitten
vanhempi
commit
fddbe71e6a

+ 1 - 1
Widget/Dashboard/DashboardData.swift

@@ -204,7 +204,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
                                     if (pathComponents.last as? NSString)?.pathExtension.lowercased() == "svg" {
                                     if (pathComponents.last as? NSString)?.pathExtension.lowercased() == "svg" {
                                         imageTemplate = true
                                         imageTemplate = true
                                     }
                                     }
-                                    if let item = CCUtility.value(forKey: "fileId", fromQueryItems: queryItems) {
+                                    if let item = queryItems?.filter({ $0.name == "fileId" }).first?.value {
                                         iconFileName = item
                                         iconFileName = item
                                     } else if pathComponents.contains("avatar") {
                                     } else if pathComponents.contains("avatar") {
                                         iconFileName = pathComponents[pathComponents.count - 2]
                                         iconFileName = pathComponents[pathComponents.count - 2]

+ 13 - 20
iOSClient/AppDelegate.swift

@@ -837,8 +837,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         var serverUrl: String = ""
         var serverUrl: String = ""
 
 
         /*
         /*
-         Example:
-         nextcloud://open-action?action=create-voice-memo&&user=marinofaggiana&url=https://cloud.nextcloud.com
+         Example: nextcloud://open-action?action=create-voice-memo&&user=marinofaggiana&url=https://cloud.nextcloud.com
          */
          */
 
 
         if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-action" {
         if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-action" {
@@ -846,16 +845,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
 
 
                 let queryItems = urlComponents.queryItems
                 let queryItems = urlComponents.queryItems
-                guard let actionScheme = CCUtility.value(forKey: "action", fromQueryItems: queryItems), let rootViewController = window?.rootViewController else { return false }
-                guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
-                guard let urlScheme = CCUtility.value(forKey: "url", fromQueryItems: queryItems) else { return false }
+                guard let actionScheme = queryItems?.filter({ $0.name == "action" }).first?.value,
+                      let userScheme = queryItems?.filter({ $0.name == "user" }).first?.value,
+                      let urlScheme = queryItems?.filter({ $0.name == "url" }).first?.value,
+                      let rootViewController = window?.rootViewController else { return false }
                 if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
                 if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
                     let message = NSLocalizedString("_the_account_", comment: "") + " " + userScheme + NSLocalizedString("_of_", comment: "") + " " + urlScheme + " " + NSLocalizedString("_does_not_exist_", comment: "")
                     let message = NSLocalizedString("_the_account_", comment: "") + " " + userScheme + NSLocalizedString("_of_", comment: "") + " " + urlScheme + " " + NSLocalizedString("_does_not_exist_", comment: "")
                     let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
                     let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
 
 
                     window?.rootViewController?.present(alertController, animated: true, completion: { })
                     window?.rootViewController?.present(alertController, animated: true, completion: { })
-
                     return false
                     return false
                 }
                 }
 
 
@@ -914,8 +913,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
         }
 
 
         /*
         /*
-         Example:
-         nextcloud://open-file?path=Talk/IMG_0000123.jpg&user=marinofaggiana&link=https://cloud.nextcloud.com/f/123
+         Example: nextcloud://open-file?path=Talk/IMG_0000123.jpg&user=marinofaggiana&link=https://cloud.nextcloud.com/f/123
          */
          */
 
 
         else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-file" {
         else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-file" {
@@ -923,19 +921,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
 
 
                 let queryItems = urlComponents.queryItems
                 let queryItems = urlComponents.queryItems
-                guard let userScheme = CCUtility.value(forKey: "user", fromQueryItems: queryItems) else { return false }
-                guard let pathScheme = CCUtility.value(forKey: "path", fromQueryItems: queryItems) else { return false }
-                guard let linkScheme = CCUtility.value(forKey: "link", fromQueryItems: queryItems) else { return false }
+                guard let userScheme = queryItems?.filter({ $0.name == "user" }).first?.value,
+                      let pathScheme = queryItems?.filter({ $0.name == "path" }).first?.value,
+                      let linkScheme = queryItems?.filter({ $0.name == "link" }).first?.value else { return false}
+
                 guard let matchedAccount = getMatchedAccount(userId: userScheme, url: linkScheme) else {
                 guard let matchedAccount = getMatchedAccount(userId: userScheme, url: linkScheme) else {
                     guard let domain = URL(string: linkScheme)?.host else { return true }
                     guard let domain = URL(string: linkScheme)?.host else { return true }
                     fileName = (pathScheme as NSString).lastPathComponent
                     fileName = (pathScheme as NSString).lastPathComponent
                     let message = String(format: NSLocalizedString("_account_not_available_", comment: ""), userScheme, domain, fileName)
                     let message = String(format: NSLocalizedString("_account_not_available_", comment: ""), userScheme, domain, fileName)
-
                     let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
                     let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
 
 
                     window?.rootViewController?.present(alertController, animated: true, completion: { })
                     window?.rootViewController?.present(alertController, animated: true, completion: { })
-
                     return false
                     return false
                 }
                 }
 
 
@@ -955,22 +952,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             return true
             return true
 
 
         /*
         /*
-         Example:
-         nextcloud://open-and-switch-account?user=marinofaggiana&url=https://cloud.nextcloud.com
+         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" {
         } else if !account.isEmpty && scheme == NCGlobal.shared.appScheme && action == "open-and-switch-account" {
             guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return false }
             guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return false }
             let queryItems = urlComponents.queryItems
             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 }
-
+            guard let userScheme = queryItems?.filter({ $0.name == "user" }).first?.value,
+                  let urlScheme = queryItems?.filter({ $0.name == "url" }).first?.value else { return false}
             // If the account doesn't exist, return false which will open the app without switching
             // If the account doesn't exist, return false which will open the app without switching
             if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
             if getMatchedAccount(userId: userScheme, url: urlScheme) == nil {
                 return false
                 return false
             }
             }
-
             // Otherwise open the app and switch accounts
             // Otherwise open the app and switch accounts
             return true
             return true
         } else {
         } else {

+ 0 - 1
iOSClient/Utility/CCUtility.h

@@ -56,7 +56,6 @@
 
 
 + (NSString *)getExtension:(NSString*)fileName;
 + (NSString *)getExtension:(NSString*)fileName;
 + (NSDate *)datetimeWithOutTime:(NSDate *)datDate;
 + (NSDate *)datetimeWithOutTime:(NSDate *)datDate;
-+ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems;
 + (NSDate *)getATime:(const char *)path;
 + (NSDate *)getATime:(const char *)path;
 
 
 @end
 @end

+ 0 - 7
iOSClient/Utility/CCUtility.m

@@ -353,13 +353,6 @@
     return datDate;
     return datDate;
 }
 }
 
 
-+ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
-    NSURLQueryItem *queryItem = [[queryItems filteredArrayUsingPredicate:predicate] firstObject];
-    return queryItem.value;
-}
-
 + (NSDate *)getATime:(const char *)path
 + (NSDate *)getATime:(const char *)path
 {
 {
     struct stat st;
     struct stat st;