Jelajahi Sumber

update fix bugs and add authentication duration

alqindiirsyam123 8 bulan lalu
induk
melakukan
cd73e90579

+ 2 - 3
ExampleCode/ExampleCode/ViewController.swift

@@ -23,9 +23,8 @@ class ViewController: UIViewController, ConnectDelegate {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        APIS.connect(appName: " SecureComm" ,apiKey: "8E784770B239FA3044A1DB44E276FB575B9BF3800ED11E200F4ACDD8FB476ABA", delegate: self, showButton: false)
-        
-        
+        APIS.connect(appName: "SecureComm" ,apiKey: "8E784770B239FA3044A1DB44E276FB575B9BF3800ED11E200F4ACDD8FB476ABA", delegate: self, showButton: false)
+        //"OneApp","38747683290F62E9667A018F490396EAE47BC16ADECD85B7E865C733E6DBD6A2"
     }
     
     override func viewDidAppear(_ animated: Bool) {

+ 1 - 1
NexilisLite/NexilisLite/Source/APIS.swift

@@ -14,7 +14,7 @@ import nuSDKService
 
 public class APIS: NSObject {
     public static func connect(appName: String, apiKey: String, delegate: ConnectDelegate, showButton: Bool = true, fromMAB: Bool = false) {
-        APIS.appNm = appName
+        APIS.appNm = appName.trimmingCharacters(in: .whitespacesAndNewlines)
         Nexilis.connect(apiKey: apiKey, delegate: delegate, showButton: showButton, fromMAB: fromMAB)
     }
     

+ 8 - 4
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -403,13 +403,13 @@ public class Nexilis: NSObject {
                                 tmp.removeValue(forKey: "alert_message")
                                 jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 if jsonData["upload_max_retry"]! != nil {
-                                    let umr = jsonData["upload_max_retry"] as? Int
-                                    Utils.setMaxRetryUpload(value: "\(umr ?? 0)")
+                                    let umr = jsonData["upload_max_retry"] as! String
+                                    Utils.setMaxRetryUpload(value: umr)
                                     jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
                                 if jsonData["upload_max_time"]! != nil {
-                                    let umt = jsonData["upload_max_time"] as? Int64
-                                    Utils.setMaxRetryTimeUpload(value: "\(umt ?? 0)")
+                                    let umt = jsonData["upload_max_time"] as! String
+                                    Utils.setMaxRetryTimeUpload(value: umt)
                                     jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
                                 if jsonData["default_fb"]! != nil {
@@ -418,6 +418,10 @@ public class Nexilis: NSObject {
                                     }
                                     jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
+                                if jsonData["authentication_duration"]! != nil {
+                                    let ad = jsonData["authentication_duration"] as! String
+                                    Utils.setAuthenticationDuration(value: ad)
+                                }
                             }
                             if let convertJsonFA = try? JSONSerialization.data(withJSONObject: jsonFA, options: .prettyPrinted) {
                                 if let jsonFAString = String(data: convertJsonFA, encoding: .utf8) {

+ 16 - 5
NexilisLite/NexilisLite/Source/Utils.swift

@@ -253,6 +253,17 @@ public final class Utils {
         return "5"
     }
     
+    static func setAuthenticationDuration(value: String) {
+        SecureUserDefaults.shared.set(value, forKey: "authentication_duration")
+    }
+
+    static func getAuthenticationDuration() -> String {
+        if let value: String = SecureUserDefaults.shared.value(forKey: "authentication_duration") {
+            return value
+        }
+        return "5"
+    }
+    
     static func setMaxRetryTimeUpload(value: String) {
         SecureUserDefaults.shared.set(value, forKey: "max_retry_time_upload")
     }
@@ -521,11 +532,9 @@ public final class Utils {
     
     public static func postDataWithCookiesAndUserAgent(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
         let apiKey: String = SecureUserDefaults.shared.value(forKey: "apiKey") ?? ""
-        let f_pin: String = User.getMyPin() ?? ""
         let parameters = [
             "app_id": APIS.getAppNm(),
-            "apikey": apiKey,
-            "f_pin": f_pin
+            "apikey": apiKey
         ]
         var jsonArray: [[String: Any]] = []
         jsonArray.append(parameters)
@@ -1184,7 +1193,9 @@ public final class Utils {
     public static func shouldRequestAuthentication() -> Bool {
         if let lastAuthTime: Date = SecureUserDefaults.shared.value(forKey: "lastAuthenticationTime") {
             let elapsedTime = Date().timeIntervalSince(lastAuthTime)
-            return elapsedTime > (60 * 5)
+            let durationAuth = Double(Utils.getAuthenticationDuration()) ?? 5
+            print("durationAuth \(durationAuth)")
+            return elapsedTime > durationAuth
         }
         return true
     }
@@ -1196,7 +1207,7 @@ public final class Utils {
         }
 
         let context = LAContext()
-        let reason = "Authenticate to access secure data"
+        let reason = "Authenticate to access secure data".localized()
 
         if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
             context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, error in