Explorar o código

Fix user agent for Text app

- still match server useragent check

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch %!s(int64=3) %!d(string=hai) anos
pai
achega
90c26d1b93

+ 7 - 2
iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift

@@ -328,7 +328,9 @@ import XLForm
 
             if self.editorId == NCGlobal.shared.editorOnlyoffice {
                 customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
-            }
+            } else if editorId == NCGlobal.shared.editorText {
+                customUserAgent = NCUtility.shared.getCustomUserAgentNCText()
+            } // else: use default
 
             NCCommunication.shared.NCTextCreateFile(fileNamePath: fileNamePath, editorId: editorId, creatorId: creatorId, templateId: templateIdentifier, customUserAgent: customUserAgent) { account, url, errorCode, errorMessage in
 
@@ -396,7 +398,10 @@ import XLForm
             var customUserAgent: String?
             if self.editorId == NCGlobal.shared.editorOnlyoffice {
                 customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
-            }
+            } else if editorId == NCGlobal.shared.editorText {
+                customUserAgent = NCUtility.shared.getCustomUserAgentNCText()
+            } // else: use default
+
             NCCommunication.shared.NCTextGetListOfTemplates(customUserAgent: customUserAgent) { account, templates, errorCode, _ in
 
                 self.indicator.stopAnimating()

+ 14 - 0
iOSClient/Utility/NCUtility.swift

@@ -28,6 +28,7 @@ import NCCommunication
 import PDFKit
 import Accelerate
 import CoreMedia
+import WebKit
 
 // MARK: - NCUtility
 
@@ -305,6 +306,19 @@ class NCUtility: NSObject {
         return true
     }
 
+    @objc func getCustomUserAgentNCText() -> String {
+        let userAgent: String = CCUtility.getUserAgent()
+        if UIDevice.current.userInterfaceIdiom == .phone {
+            // NOTE: Hardcoded (May 2022)
+            // Tested for iPhone SE (1st), iOS 12; iPhone Pro Max, iOS 15.4; iPhone X,
+            // 605.1.15 = WebKit build version
+            // 15E148 = frozen iOS build number according to: https://chromestatus.com/feature/4558585463832576
+            return userAgent + " " + "AppleWebKit/605.1.15 Mobile/15E148"
+        } else {
+            return userAgent
+        }
+    }
+
     @objc func getCustomUserAgentOnlyOffice() -> String {
 
         let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!

+ 2 - 0
iOSClient/Viewer/NCViewer.swift

@@ -152,6 +152,8 @@ class NCViewer: NSObject {
 
                         if editor == NCGlobal.shared.editorOnlyoffice {
                             customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
+                        } else {
+                            customUserAgent = NCUtility.shared.getCustomUserAgentNCText()
                         }
 
                         NCUtility.shared.startActivityIndicator(backgroundView: viewController.view, blurEffect: true)

+ 3 - 3
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -72,9 +72,9 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
 
         if editor == NCGlobal.shared.editorOnlyoffice {
             webView.customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
-        } else {
-            webView.customUserAgent = CCUtility.getUserAgent()
-        }
+        } else if editor == NCGlobal.shared.editorText {
+            webView.customUserAgent = NCUtility.shared.getCustomUserAgentNCText()
+        } // else: use default
 
         webView.load(request)
     }