Selaa lähdekoodia

update for fix bugs, embed and add new APIS

alqindiirsyam 1 viikko sitten
vanhempi
commit
cea6161a20

BIN
.DS_Store


+ 6 - 6
AppBuilder/AppBuilder/Info.plist

@@ -97,12 +97,6 @@
 	</dict>
 	<key>CFBundleIdentifier</key>
 	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
-    <key>UIFileSharingEnabled</key>
-    <string>false</string>
-    <key>NSFileProtectionComplete</key>
-    <true/>
-    <key>NSFaceIDUsageDescription</key>
-    <string>$(PRODUCT_NAME) Authentication with TouchId or FaceID for Security App</string>
 	<key>CFBundleInfoDictionaryVersion</key>
 	<string>6.0</string>
 	<key>CFBundleName</key>
@@ -129,6 +123,12 @@
 		<key>NSAllowsArbitraryLoads</key>
 		<true/>
 	</dict>
+    <key>UIFileSharingEnabled</key>
+    <string>false</string>
+    <key>NSFileProtectionComplete</key>
+    <true/>
+    <key>NSFaceIDUsageDescription</key>
+    <string>$(PRODUCT_NAME) Authentication with TouchId or FaceID for Security App</string>
     <key>NSCameraUsageDescription</key>
     <string>This app requires Camera access for Video Call, Conference Room, Content Creation and Live Streaming.</string>
     <key>NSDocumentsFolderUsageDescription</key>

BIN
ExampleCode/.DS_Store


BIN
NexilisLite/.DS_Store


+ 14 - 2
NexilisLite/NexilisLite.xcodeproj/project.pbxproj

@@ -245,6 +245,9 @@
 		CD9551692A664BDB00AF6476 /* Poppins-SemiBoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = CD9551332A664BD400AF6476 /* Poppins-SemiBoldItalic.otf */; };
 		CD95516A2A664BDB00AF6476 /* Poppins-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = CD95513A2A664BD400AF6476 /* Poppins-BoldItalic.otf */; };
 		CD95516B2A664BDB00AF6476 /* Poppins-ExtraLightItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = CD9551382A664BD400AF6476 /* Poppins-ExtraLightItalic.otf */; };
+		CD962CFD2E420B5300A7BDA5 /* TOTPGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD962CFC2E420B5300A7BDA5 /* TOTPGenerator.swift */; };
+		CD962CFE2E420B5300A7BDA5 /* MFAViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD962CFB2E420B5300A7BDA5 /* MFAViewController.swift */; };
+		CD962CFF2E420B5300A7BDA5 /* MFABiometricOnlyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD962CFA2E420B5300A7BDA5 /* MFABiometricOnlyViewController.swift */; };
 		CD9829B72A3C07CB009F6743 /* SeminarListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9829B62A3C07CB009F6743 /* SeminarListViewController.swift */; };
 		CDA461222AB99E09001CD010 /* ConfigureFloatingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA461212AB99E09001CD010 /* ConfigureFloatingButton.swift */; };
 		CDB21B2E2BA9998400EC5280 /* pb_def_icon_mode2.gif in Resources */ = {isa = PBXBuildFile; fileRef = CDB21B2B2BA9998400EC5280 /* pb_def_icon_mode2.gif */; };
@@ -535,6 +538,9 @@
 		CD9551432A664BD400AF6476 /* Poppins-BlackItalic.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Poppins-BlackItalic.otf"; sourceTree = "<group>"; };
 		CD9551442A664BD400AF6476 /* Poppins-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Poppins-Regular.otf"; sourceTree = "<group>"; };
 		CD9551452A664BD400AF6476 /* Poppins-ExtraBold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Poppins-ExtraBold.otf"; sourceTree = "<group>"; };
+		CD962CFA2E420B5300A7BDA5 /* MFABiometricOnlyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFABiometricOnlyViewController.swift; sourceTree = "<group>"; };
+		CD962CFB2E420B5300A7BDA5 /* MFAViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFAViewController.swift; sourceTree = "<group>"; };
+		CD962CFC2E420B5300A7BDA5 /* TOTPGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TOTPGenerator.swift; sourceTree = "<group>"; };
 		CD9829B62A3C07CB009F6743 /* SeminarListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SeminarListViewController.swift; sourceTree = "<group>"; };
 		CDA461212AB99E09001CD010 /* ConfigureFloatingButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigureFloatingButton.swift; sourceTree = "<group>"; };
 		CDB21B2B2BA9998400EC5280 /* pb_def_icon_mode2.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = pb_def_icon_mode2.gif; sourceTree = "<group>"; };
@@ -794,8 +800,6 @@
 		CD1E71892A0BA86100BF871F /* Control */ = {
 			isa = PBXGroup;
 			children = (
-				CD21CA582E0AA0A200DA6B77 /* SignInOption.swift */,
-				1258BCB52D82D71200EFF5BD /* ChatWallpaperViewController.swift */,
 				CD1E71AB2A0BA86100BF871F /* AddFriendTableViewController.swift */,
 				CD1E71AD2A0BA86100BF871F /* AudienceViewController.swift */,
 				CD1E719B2A0BA86100BF871F /* BackupRestoreOption.swift */,
@@ -809,6 +813,7 @@
 				CD1E71922A0BA86100BF871F /* ChangeNamePassswordViewController.swift */,
 				CD1E719D2A0BA86100BF871F /* ChangeNameTableViewController.swift */,
 				CD1E71962A0BA86100BF871F /* ChangePasswordViewController.swift */,
+				1258BCB52D82D71200EFF5BD /* ChatWallpaperViewController.swift */,
 				CD1E718F2A0BA86100BF871F /* CheckConnection.swift */,
 				CDA461212AB99E09001CD010 /* ConfigureFloatingButton.swift */,
 				CD1E71932A0BA86100BF871F /* ContactChatViewController.swift */,
@@ -822,6 +827,8 @@
 				CD1E718E2A0BA86100BF871F /* HistoryBroadcastViewController.swift */,
 				CD1E719C2A0BA86100BF871F /* HistoryCCViewController.swift */,
 				CD1E71A42A0BA86100BF871F /* ImageVideoPicker.swift */,
+				CD962CFA2E420B5300A7BDA5 /* MFABiometricOnlyViewController.swift */,
+				CD962CFB2E420B5300A7BDA5 /* MFAViewController.swift */,
 				CD1E719E2A0BA86100BF871F /* NotificationSound.swift */,
 				CD1E71A62A0BA86100BF871F /* ProfileViewController.swift */,
 				CD2B01222D43961E00C11B20 /* QRProfileController.swift */,
@@ -831,7 +838,9 @@
 				CD1E71A12A0BA86100BF871F /* SetInternalCSAccount.swift */,
 				CD1E71AA2A0BA86100BF871F /* SetOfficerBNI.swift */,
 				CD1E71992A0BA86100BF871F /* SettingTableViewController.swift */,
+				CD21CA582E0AA0A200DA6B77 /* SignInOption.swift */,
 				CD1E71902A0BA86100BF871F /* SignUpSignIn.swift */,
+				CD962CFC2E420B5300A7BDA5 /* TOTPGenerator.swift */,
 				CD1E719F2A0BA86100BF871F /* TypeViewController.swift */,
 				CD1E71A02A0BA86100BF871F /* VerifyEmail.swift */,
 			);
@@ -1432,6 +1441,9 @@
 				CD5A73AF2A77642D000541A5 /* ListGroupImages.swift in Sources */,
 				CD1E720F2A0BA86100BF871F /* Download.swift in Sources */,
 				CD1E725D2A0BA86100BF871F /* WhiteboardDelegate.swift in Sources */,
+				CD962CFD2E420B5300A7BDA5 /* TOTPGenerator.swift in Sources */,
+				CD962CFE2E420B5300A7BDA5 /* MFAViewController.swift in Sources */,
+				CD962CFF2E420B5300A7BDA5 /* MFABiometricOnlyViewController.swift in Sources */,
 				CD1E721B2A0BA86100BF871F /* Nexilis.swift in Sources */,
 				CD1E72102A0BA86100BF871F /* Extension.swift in Sources */,
 				CD1E724C2A0BA86100BF871F /* NotificationSound.swift in Sources */,

+ 62 - 4
NexilisLite/NexilisLite/Source/APIS.swift

@@ -18,9 +18,9 @@ import Intents
 public class APIS: NSObject {
     private static var isAlertPresented = false
     private static var transitioningDelegateRef: ZoomTransitioningDelegate?
-    public static func connect(appName: String, apiKey: String, delegate: ConnectDelegate, showButton: Bool = true, fromMAB: Bool = false) {
+    public static func connect(appName: String, apiKey: String, userName: String = "", delegate: ConnectDelegate, showButton: Bool = true, fromMAB: Bool = false) {
         APIS.appNm = appName.trimmingCharacters(in: .whitespacesAndNewlines)
-        Nexilis.connect(apiKey: apiKey, delegate: delegate, showButton: showButton, fromMAB: fromMAB)
+        Nexilis.connect(apiKey: apiKey, userId: userName, delegate: delegate, showButton: showButton, fromMAB: fromMAB)
     }
     
     public static func getTotalCounter() -> Int32 {
@@ -197,7 +197,7 @@ public class APIS: NSObject {
         }
     }
     
-    public static func openChat() {
+    public static func openChat(withoutUCList: Bool = false) {
         let isChangeProfile = Utils.getSetProfile()
         if !isChangeProfile {
             APIS.showChangeProfile()
@@ -206,7 +206,7 @@ public class APIS: NSObject {
         let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
         Utils.addBackground(view: navigationController.view)
         let vc = navigationController.topViewController as! ContactChatViewController
-        vc.noUCList = true
+        vc.noUCList = withoutUCList
         navigationController.defaultStyle()
         if UIApplication.shared.visibleViewController?.navigationController != nil {
             UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
@@ -975,6 +975,64 @@ public class APIS: NSObject {
         }
     }
     
+    public static func logOut() {
+        let isChangeProfile = Utils.getSetProfile()
+        if !isChangeProfile {
+            APIS.showChangeProfile()
+            return
+        }
+        Nexilis.destroyAll()
+        _ = Nexilis.write(message: CoreMessage_TMessageBank.getLogout())
+    }
+    
+    public static func openPPOB() {
+        let isChangeProfile = Utils.getSetProfile()
+        if !isChangeProfile {
+            APIS.showChangeProfile()
+            return
+        }
+        let idx = Nexilis.IDX_PPOB
+        let url = getURLFB(idx: idx)
+        print("HUHU: \(idx) <><> \(url)")
+        Nexilis.buttonClicked(index: idx, id: url)
+    }
+    
+    public static func openSocialCommerce() {
+        let isChangeProfile = Utils.getSetProfile()
+        if !isChangeProfile {
+            APIS.showChangeProfile()
+            return
+        }
+        let idx = Nexilis.IDX_SOCIAL_COMMERCE
+        let url = getURLFB(idx: idx)
+        Nexilis.buttonClicked(index: idx, id: url)
+    }
+    
+    private static func getURLFB(idx: Int) -> String {
+        let data = Utils.getHistoryPullFB()
+        if !data.isEmpty {
+            if let jsonArray = try! JSONSerialization.jsonObject(with: data.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
+                let filteredData = jsonArray.filter({
+                    let package_id = ($0["package_id"] as! String)
+                    if package_id.contains("_fb") {
+                        let listSplit = package_id.split(separator: "_", maxSplits: 2)
+                        let numIdx = listSplit[listSplit.firstIndex(where: { $0.contains("fb") }) ?? 0]
+                        let indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count)) ?? 0
+                        return indexTap == idx
+                    }
+                    return package_id.isEmpty
+                })
+                if filteredData.count != 0 {
+                    let data = filteredData[0] as? [String: Any]
+                    let package_id = data?["package_id"] as! String
+                    let listSplit = package_id.split(separator: "_", maxSplits: 2)
+                    return String(listSplit[2])
+                }
+            }
+        }
+        return ""
+    }
+    
     public static func sendSMS(phoneNumber: String, message: String = ""){
         let formattedNumber = phoneNumber.replacingOccurrences(of: "-", with: "")
         let urlStringEncoded = message.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)

+ 22 - 0
NexilisLite/NexilisLite/Source/CoreMessage_TMessageBank.swift

@@ -32,6 +32,19 @@ public class CoreMessage_TMessageBank {
         return tmessage
     }
     
+    public static func getSignInApi(api: String, p_pin: String, name: String) -> TMessage {
+        let tmessage = TMessage()
+        tmessage.mCode = CoreMessage_TMessageCode.SEND_SIGNIN
+        tmessage.mStatus = CoreMessage_TMessageUtil.getTID()
+        tmessage.mBodies[CoreMessage_TMessageKey.NAME] = name
+        tmessage.mBodies[CoreMessage_TMessageKey.API] = api
+        tmessage.mBodies[CoreMessage_TMessageKey.ANDROID_APP_NAME] = APIS.getAppNm()
+        tmessage.mBodies[CoreMessage_TMessageKey.CPAAS_VERSION] = Utils.CPAAS_VERSION
+        tmessage.mBodies[CoreMessage_TMessageKey.ANDROID_PACKAGE_NAME] = (Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String) ?? ""
+        tmessage.mPIN = p_pin
+        return tmessage
+    }
+    
     public static func getSignIn(p_name: String, p_password: String) -> TMessage {
         let tmessage = TMessage()
         tmessage.mCode = CoreMessage_TMessageCode.SEND_SIGNIN
@@ -2858,4 +2871,13 @@ public class CoreMessage_TMessageBank {
         return tMessage
     }
     
+    public static func getLogout() -> TMessage {
+        let tMessage = NexilisLite.TMessage()
+        let me = User.getMyPin() ?? ""
+        tMessage.mPIN = me
+        tMessage.mCode = CoreMessage_TMessageCode.LOGOUT
+        tMessage.mStatus = CoreMessage_TMessageUtil.getTID()
+        return tMessage
+    }
+    
 }

+ 4 - 4
NexilisLite/NexilisLite/Source/FloatingButton/FloatingButton.swift

@@ -666,11 +666,11 @@ public class FloatingButton: UIView, UIGestureRecognizerDelegate {
         var app_id = sender.accessibilityIdentifier!
         var indexTap = 0
         if package_id.contains("_fb"){
-            let listSplit = package_id.split(separator: "_", maxSplits: 1)
+            let listSplit = package_id.split(separator: "_", maxSplits: 2)
             let numIdx = listSplit[listSplit.firstIndex(where: { $0.contains("fb") }) ?? 0]
-            indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count))!
-            if listSplit.count == 2 {
-                app_id = String(listSplit[1])
+            indexTap = Int(String(numIdx).substring(from: 2, to: numIdx.count)) ?? 0
+            if listSplit.count == 3 {
+                app_id = String(listSplit[2])
             }
         }
         Nexilis.buttonClicked(index: indexTap, id: app_id)

+ 4 - 66
NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -262,72 +262,10 @@ class IncomingThread {
         if let packetId = message.mBodies[CoreMessage_TMessageKey.PACKET_ID] {
             _ = Nexilis.responseString(packetId: packetId, message: "00", timeout: 3000)
         }
-        DispatchQueue.global().async {
-            let viewController = UIApplication.shared.visibleViewController
-            DispatchQueue.main.async {
-                if !CheckConnection.isConnectedToNetwork()  || API.nGetCLXConnState() == 0 {
-                    let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
-                    imageView.tintColor = .white
-                    let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
-                    banner.show()
-                    return
-                }
-                Nexilis.showLoader()
-                let imageView = UIImageView(image: UIImage(systemName: "info.circle"))
-                imageView.tintColor = .white
-                let banner = FloatingNotificationBanner(title: "You have requested Call Center, please wait for response.".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .info, colors: nil, iconPosition: .center)
-                banner.show()
-            }
-            let apiKey = Nexilis.sAPIKey
-            var id = Utils.getConnectionID()
-            if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000) {
-                id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
-                if(!id.isEmpty){
-//                            Nexilis.changeUser(f_pin: id)
-                    SecureUserDefaults.shared.set(id, forKey: "me")
-                    APIS.sendPushToken(Utils.getTokenAPN(), isResend: true)
-                    Nexilis.sendVersionToBE()
-                    Utils.setProfile(value: false)
-                    if Utils.getForceAnonymous() {
-                        viewController?.deleteAllRecordDatabase()
-                        SecureUserDefaults.shared.removeValue(forKey: "device_id")
-//                        FileEncryption.shared.wipeFolder()
-                        Nexilis.destroyAll()
-                    }
-                    DispatchQueue.main.async {
-                        Nexilis.hideLoader(completion: {
-                            if Nexilis.showFB {
-                                Nexilis.floatingButton.removeFromSuperview()
-                                Nexilis.floatingButton = FloatingButton()
-                                Nexilis.addFB()
-                            }
-                            var dataImage: [AnyHashable : Any] = [:]
-                            dataImage["name"] = ""
-                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
-                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
-                        })
-                    }
-                } else {
-                    DispatchQueue.main.async {
-                        Nexilis.hideLoader(completion: {
-                            let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
-                            imageView.tintColor = .white
-                            let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
-                            banner.show()
-                        })
-                    }
-                }
-            } else {
-                DispatchQueue.main.async {
-                    Nexilis.hideLoader(completion: {
-                        let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
-                        imageView.tintColor = .white
-                        let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
-                        banner.show()
-                    })
-                }
-            }
-        }
+        UIApplication.shared.visibleViewController?.deleteAllRecordDatabase()
+        Nexilis.floatingButton.removeFromSuperview()
+        SecureUserDefaults.shared.removeValue(forKey: "me")
+        Utils.setProfile(value: false)
         ack(message: message)
     }
     

+ 20 - 4
NexilisLite/NexilisLite/Source/MasterKeyUtil.swift

@@ -110,12 +110,18 @@ public class MasterKeyUtil {
 
                 if !result {
                     DispatchQueue.main.async {
-                        Utils.showAlert(
-                            title: "Failed to get Master Key".localized(),
-                            message: "Biometric authentication hasn't been set up/Biometric invalid.".localized()
-                        )
+//                        self.showAlert(
+//                            title: "Failed to get Master Key".localized(),
+//                            message: "Biometric authentication hasn't been set up/Biometric invalid.".localized()
+//                        )
+                        let alertController = UIAlertController(title: "Failed to Verify Identity".localized(), message: "Biometric authentication hasn't been set up/Biometric invalid.".localized(), preferredStyle: .alert)
+                        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {(_) in
+                            semaphore.signal()
+                        }))
+                        UIApplication.shared.visibleViewController?.present(alertController, animated: true)
                     }
                     thrownError = NSError(domain: "KeychainError", code: -99, userInfo: nil)
+                    semaphore.wait()
                     return
                 }
             }
@@ -152,6 +158,16 @@ public class MasterKeyUtil {
         return key
     }
     
+    private func showAlert(title: String, message: String) {
+        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
+        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {(_) in
+            if Database.shared.database == nil {
+                exit(979)
+            }
+        }))
+        UIApplication.shared.visibleViewController?.present(alertController, animated: true)
+    }
+    
     func getPrefsKey() throws -> SymmetricKey {
         let query: [String: Any] = [
             kSecClass as String: kSecClassKey,

+ 65 - 10
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -131,6 +131,8 @@ public class Nexilis: NSObject {
     private static var ringbacktonePlayer: AVAudioPlayer?
     private static var busyPlayer: AVAudioPlayer?
     static var sharedAudioPlayer: AVAudioPlayer?
+    
+    private static var iRetryCheckSignInSignUp = 0
 //    static var firstCall = true
     
     private func createDelegate() {
@@ -141,7 +143,7 @@ public class Nexilis: NSObject {
         personInfoDelegate = self
     }
     
-    public static func connect(apiKey: String, delegate: ConnectDelegate, showButton: Bool = true, fromMAB: Bool = false) {
+    public static func connect(apiKey: String, userId:String = "", delegate: ConnectDelegate, showButton: Bool = true, fromMAB: Bool = false) {
         showFB = showButton
         Nexilis.fromMAB = fromMAB
         
@@ -217,7 +219,7 @@ public class Nexilis: NSObject {
                 Nexilis.PORT = Int(address.components(separatedBy: ":")[1]) ?? 0
                 if id.isEmpty {
                     let sDID = UIDevice.current.identifierForVendor?.uuidString ?? "UNK-DEVICE"
-                    id = String(sDID[sDID.index(sDID.endIndex, offsetBy: -5)...])
+                    id = String(sDID[sDID.index(sDID.endIndex, offsetBy: -5)...]) + "\(Date().currentTimeMillis())"
                     Utils.setConnectionID(value: id)
                 }
                 try API.initConnection(sAPIK: apiKey, cbiI: Callback(), sTCPAddr: Nexilis.ADDRESS, nTCPPort: Nexilis.PORT, sUserID: id, sStartWH: "09:00")
@@ -225,13 +227,63 @@ public class Nexilis: NSObject {
                     Thread.sleep(forTimeInterval: 0.5)
                 }
                 if(User.getMyPin() == nil) {
-                    if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id), timeout: 30 * 1000){
-                        id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
-                        let enable_signup = (response.getBody(key: CoreMessage_TMessageKey.IS_ENABLED_ANONYMOUS, default_value: "0")) == "1"
-                        Utils.setForceAnonymous(value: enable_signup)
-                        if(!id.isEmpty) {
-                            SecureUserDefaults.shared.set(id, forKey: "me")
+                    iRetryCheckSignInSignUp = 0
+                    let maxWaitTime: TimeInterval = 60 * 60 // 1 hour in seconds
+                    let t0 = Date().currentTimeMillis()
+                    
+                    do {
+                        while iRetryCheckSignInSignUp <= 30 || Date().currentTimeMillis() - t0 <= Int(maxWaitTime) {
+                            var tmessage = CoreMessage_TMessageBank.getSignUpApi(api: apiKey, p_pin: id)
+                            if !userId.isEmpty {
+                                tmessage = CoreMessage_TMessageBank.getSignInApi(api: apiKey, p_pin: id, name: userId)
+                            }
+                            if let response = Nexilis.writeSync(message: tmessage, timeout: 30 * 1000) {
+                                if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "11" {
+                                    let message = "94:Unregistered user"
+                                    delegate.onFailed(error: message)
+                                    sendStateToServer(s: message)
+                                    print("checkSignInSignUp sleep 30s before retrying send to server..")
+                                    Thread.sleep(forTimeInterval: 30)
+                                } else if !response.isOk() {
+                                    let message = "99:Something went wrong. Invalid response, please check your connection.."
+                                    delegate.onFailed(error: message)
+                                    sendStateToServer(s: message)
+                                    print("checkSignInSignUp sleep 30s before retrying send to server..")
+                                    Thread.sleep(forTimeInterval: 30)
+                                } else {
+                                    SecureUserDefaults.shared.set(id, forKey: "device_id")
+                                    id = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
+                                    var enable_signup = (response.getBody(key: CoreMessage_TMessageKey.IS_ENABLED_ANONYMOUS, default_value: "0")) == "1"
+                                    if !enable_signup && !userId.isEmpty {
+                                        enable_signup = true
+                                        Utils.setProfile(value: true)
+                                    }
+                                    Utils.setForceAnonymous(value: enable_signup)
+                                    if(!id.isEmpty) {
+                                        SecureUserDefaults.shared.set(id, forKey: "me")
+                                    }
+                                    break
+                                }
+                            } else {
+                                iRetryCheckSignInSignUp += 1
+
+                                if iRetryCheckSignInSignUp >= 30 {
+                                    let message: String
+                                    if !userId.isEmpty {
+                                        message = "99:Something went wrong while Sign-In. Please check your connection.."
+                                    } else {
+                                        message = "99:Something went wrong while Sign-Up. Please check your connection.."
+                                    }
+                                    delegate.onFailed(error: message)
+                                    sendStateToServer(s: message)
+                                }
+
+                                print("checkSignInSignUp sleep 30s before retrying send to server..")
+                                Thread.sleep(forTimeInterval: 30)
+                            }
                         }
+                    } catch {
+                        print("checkSignInSignUp error: \(error.localizedDescription)")
                     }
                 }
 
@@ -246,7 +298,10 @@ public class Nexilis: NSObject {
                 
                 if let me = User.getMyPin() {
                     if Utils.getSetProfile() {
-                        if Utils.getSecureFolderOffline() != "0" {
+                        if Utils.getSecureFolderOffline() != "0" || !userId.isEmpty {
+                            while FileEncryption.shared.aesKey == nil {
+                                Thread.sleep(forTimeInterval: 1)
+                            }
                             _ = Database.shared.openDatabase()
                         }
                         Database.shared.database?.inTransaction({ (fmdb, rollback) in
@@ -502,7 +557,7 @@ public class Nexilis: NSObject {
                 "state": s
             ]
             Utils.postDataWithCookiesAndUserAgent(from: URL(string: Utils.getDomainOpr() + "logging")!, parameter: parameter) { data, response, error in
-                print("\(response)")
+//                print("\(response)")
             }
         }
     }

+ 0 - 10
NexilisLite/NexilisLite/Source/Utils.swift

@@ -1572,16 +1572,6 @@ public final class Utils {
             completion(false, "Biometric authentication is not available")
         }
     }
-    
-    static func showAlert(title: String, message: String) {
-        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {(_) in
-            if Database.shared.database == nil {
-                exit(979)
-            }
-        }))
-        UIApplication.shared.visibleViewController?.present(alertController, animated: true)
-    }
 }
 public extension UIImage {
     var jpeg: Data? { jpegData(compressionQuality: 1) }  // QUALITY min = 0 / max = 1

+ 3 - 1
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -7121,7 +7121,9 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
                         let fileManager = FileManager.default
                         let tempURL = fileManager.temporaryDirectory.appendingPathComponent(sender.labelFile.text ?? "")
                         do {
-                            try fileManager.copyItem(at: urlFile, to: tempURL)
+                            if !fileManager.fileExists(atPath: tempURL.path) {
+                                try fileManager.copyItem(at: urlFile, to: tempURL)
+                            }
                             let activityViewController = UIActivityViewController(activityItems: [tempURL], applicationActivities: nil)
                             activityViewController.popoverPresentationController?.sourceView = vcHandleFile.view
                             vcHandleFile.present(activityViewController, animated: true, completion: nil)

+ 3 - 1
NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -8507,7 +8507,9 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
                         let fileManager = FileManager.default
                         let tempURL = fileManager.temporaryDirectory.appendingPathComponent(sender.labelFile.text ?? "")
                         do {
-                            try fileManager.copyItem(at: urlFile, to: tempURL)
+                            if !fileManager.fileExists(atPath: tempURL.path) {
+                                try fileManager.copyItem(at: urlFile, to: tempURL)
+                            }
                             let activityViewController = UIActivityViewController(activityItems: [tempURL], applicationActivities: nil)
                             activityViewController.popoverPresentationController?.sourceView = vcHandleFile.view
                             vcHandleFile.present(activityViewController, animated: true, completion: nil)

+ 3 - 1
NexilisLite/NexilisLite/Source/View/Chat/EditorStarMessages.swift

@@ -1303,7 +1303,9 @@ public class EditorStarMessages: UIViewController, UITableViewDataSource, UITabl
                         let fileManager = FileManager.default
                         let tempURL = fileManager.temporaryDirectory.appendingPathComponent(sender.labelFile.text ?? "")
                         do {
-                            try fileManager.copyItem(at: urlFile, to: tempURL)
+                            if !fileManager.fileExists(atPath: tempURL.path) {
+                                try fileManager.copyItem(at: urlFile, to: tempURL)
+                            }
                             let activityViewController = UIActivityViewController(activityItems: [tempURL], applicationActivities: nil)
                             activityViewController.popoverPresentationController?.sourceView = vcHandleFile.view
                             vcHandleFile.present(activityViewController, animated: true, completion: nil)

+ 1 - 1
NexilisLite/NexilisLite/Source/View/Chat/PreviewAttachmentImageVideo.swift

@@ -805,7 +805,7 @@ class PreviewAttachmentImageVideo: UIViewController, UIScrollViewDelegate, UITex
                        handler:@escaping (_ exportSession: AVAssetExportSession?) -> Void) {
         let urlAsset = AVURLAsset(url: inputURL, options: nil)
         guard let exportSession = AVAssetExportSession(asset: urlAsset,
-                                                       presetName: AVAssetExportPresetMediumQuality) else {
+                                                       presetName: AVAssetExportPresetHighestQuality) else {
             handler(nil)
             
             return

+ 17 - 25
StreamShield/StreamShield/Source/SecurityShield.swift

@@ -354,31 +354,10 @@ private class Process: NSObject, CLLocationManagerDelegate {
                         
                     }
                     if Preference.getPreventKeylogger() || Preference.getPreventScreenCapture() {
-                        DispatchQueue.main.async(execute: {
-                            let alert = SSLibAlertController(title: Preference.getPreventKeylogger() ? Preference.getKeyloggerAlertTitle() : Preference.getCheckScreenCaptureAlertTitle(), message: Preference.getPreventKeylogger() ? Preference.getKeyloggerAlertMessage() : Preference.getScreenCaptureAlertMessage(), preferredStyle: .alert)
-                            if Preference.getPreventKeyloggerAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE || Preference.getPreventScreenCaptureAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
-                                alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
-                                    NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
-                                    DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
-                                        if let window = UIApplication.shared.windows.first {
-                                            makeSecure(window: window)
-                                        }
-                                    })
-                                }))
-                                if UIApplication.shared.visibleViewController?.navigationController != nil {
-                                    UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
-                                } else {
-                                    UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
-                                }
-                            } else {
-                                alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
-                                    exit(-101)
-                                }))
-                                if UIApplication.shared.visibleViewController?.navigationController != nil {
-                                    UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
-                                } else {
-                                    UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
-                                }
+                        NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
+                        DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
+                            if let window = UIApplication.shared.windows.first {
+                                makeSecure(window: window)
                             }
                         })
                     } else {
@@ -471,36 +450,42 @@ private class Process: NSObject, CLLocationManagerDelegate {
     static func subCheck(_ typeSecurity : Int) {
         if typeSecurity == 1 {
             if checkEmulator() {
+//                print("ERROR 1")
                 sendShieldErrorLog(code: 5)
                 return
             }
             subCheck(2)
         } else if typeSecurity == 2 {
             if checkRootedDevice() {
+//                print("ERROR 2")
                 sendShieldErrorLog(code: 4)
                 return
             }
             subCheck(3)
         } else if typeSecurity == 3 {
             if checkOutdatedOS() {
+//                print("ERROR 3")
                 sendShieldErrorLog(code: 12)
                 return
             }
             subCheck(4)
         } else if typeSecurity == 4 {
             if checkTempering() {
+//                print("ERROR 4")
                 sendShieldErrorLog(code: 14)
                 return
             }
             subCheck(5)
         } else if typeSecurity == 5 {
             if checkHooked() {
+//                print("ERROR 5")
                 sendShieldErrorLog(code: 22)
                 return
             }
             subCheck(6)
         } else if typeSecurity == 6 {
             if checkDebugging() {
+//                print("ERROR 6")
                 sendShieldErrorLog(code: 6)
                 return
             }
@@ -509,42 +494,49 @@ private class Process: NSObject, CLLocationManagerDelegate {
             NotificationCenter.default.addObserver(self, selector: #selector(screenDidConnect), name: UIScreen.didConnectNotification, object: nil)
             NotificationCenter.default.addObserver(self, selector: #selector(screenDidDisconnect), name: UIScreen.didDisconnectNotification, object: nil)
             if checkScreenCasting() {
+//                print("ERROR 7")
                 sendShieldErrorLog(code: 7)
                 return
             }
             subCheck(8)
         } else if typeSecurity == 8 {
             if checkScreenOverlay() {
+//                print("ERROR 8")
                 sendShieldErrorLog(code: 15)
                 return
             }
             subCheck(9)
         } else if typeSecurity == 9 {
             if checkCallForward() {
+//                print("ERROR 9")
                 sendShieldErrorLog(code: 2)
                 return
             }
             subCheck(10)
         } else if typeSecurity == 10 {
             if checkMultipleLogin() {
+//                print("ERROR 10")
                 sendShieldErrorLog(code: 1)
                 return
             }
             subCheck(11)
         } else if typeSecurity == 11 {
             if checkSimSwap() {
+//                print("ERROR 11")
                 sendShieldErrorLog(code: 3)
                 return
             }
             subCheck(12)
         } else if typeSecurity == 12 {
             if checkGeovelocity() {
+//                print("ERROR 12")
                 sendShieldErrorLog(code: 21)
                 return
             }
             subCheck(13)
         } else if typeSecurity == 13 {
             if checkBehaviourAnalysis() {
+//                print("ERROR 13")
                 sendShieldErrorLog(code: 17)
                 return
             }