瀏覽代碼

【会员系统】网络错误提示语在主线程弹出

dinglingui 3 月之前
父節點
當前提交
e954e3cc15

+ 8 - 6
PDF Office/PDF Master/MemberCenter/View/KMEnterNewPasswordView.swift

@@ -174,12 +174,14 @@ class KMEnterNewPasswordView: KMBaseXibView {
             if success {
                 self.skipSignUpView()
             } else {
-                let alert = NSAlert()
-                alert.messageText = NSLocalizedString(msg, comment: "")
-                alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                let result = alert.runModal()
-                if (result == .alertFirstButtonReturn) {
-                    self.skipSignUpView()
+                DispatchQueue.main.async {
+                    let alert = NSAlert()
+                    alert.messageText = NSLocalizedString(msg, comment: "")
+                    alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                    let result = alert.runModal()
+                    if (result == .alertFirstButtonReturn) {
+                        self.skipSignUpView()
+                    }
                 }
             }
         }

+ 8 - 6
PDF Office/PDF Master/MemberCenter/View/KMForgotPasswordView.swift

@@ -188,12 +188,14 @@ class KMForgotPasswordView: KMBaseXibView {
             if success {
                 self.skipEnterVerificationCodeView()
             } else {
-                let alert = NSAlert()
-                alert.messageText = NSLocalizedString("This email has not been registered, please log in through the account verification code, we will automatically register an account for you.", tableName: "MemberCenterLocalizable", comment: "")
-                alert.addButton(withTitle: "OK")
-                let response = alert.runModal()
-                if response == .alertFirstButtonReturn {
-                    self.skipSignUpView()
+                DispatchQueue.main.async {
+                    let alert = NSAlert()
+                    alert.messageText = NSLocalizedString("This email has not been registered, please log in through the account verification code, we will automatically register an account for you.", tableName: "MemberCenterLocalizable", comment: "")
+                    alert.addButton(withTitle: "OK")
+                    let response = alert.runModal()
+                    if response == .alertFirstButtonReturn {
+                        self.skipSignUpView()
+                    }
                 }
             }
         }

+ 34 - 27
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -236,16 +236,19 @@ class KMSignUpViewModel: ObservableObject {
             code = password
         }
         if !privacyState {
-            let alert = NSAlert()
-            alert.messageText = NSLocalizedString("Please agree and check the above agreement first.", tableName: "MemberCenterLocalizable", comment: "")
-            alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-//            alert.beginSheetModal(for: NSApp.mainWindow!)
-            let result = alert.runModal()
-            if (result == .alertFirstButtonReturn) {
-                privacyState = true
+            DispatchQueue.main.async {
+                
+                let alert = NSAlert()
+                alert.messageText = NSLocalizedString("Please agree and check the above agreement first.", tableName: "MemberCenterLocalizable", comment: "")
+                alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                //            alert.beginSheetModal(for: NSApp.mainWindow!)
+                let result = alert.runModal()
+                if (result == .alertFirstButtonReturn) {
+                    privacyState = true
+                }
+                
+                callback?(nil)
             }
-            
-            callback?(nil)
             return
         }
         KMMemberCenterManager.manager.emailLogin(email: email, code: code, type: signUpState) { [weak self] success, wrapper  in
@@ -279,14 +282,16 @@ class KMSignUpViewModel: ObservableObject {
             } else {
                 if(resultDict.code == 305) {
                     if KMMemberCenterManager.manager.isConnectionAvailable() == false {
-                        let alert = NSAlert()
-                        alert.alertStyle = .critical
-                        alert.messageText = NSLocalizedString("Error Information", comment: "")
-                        alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
-                        alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                        alert.runModal()
-                        
-                        callback?(false)
+                        DispatchQueue.main.async {
+                            let alert = NSAlert()
+                            alert.alertStyle = .critical
+                            alert.messageText = NSLocalizedString("Error Information", comment: "")
+                            alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
+                            alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                            alert.runModal()
+                            
+                            callback?(false)
+                        }
                         return
                     }
                     KMMemberCenterManager.manager.getUserDeviceList(email: self.email) { [weak self] success, result in
@@ -303,16 +308,18 @@ class KMSignUpViewModel: ObservableObject {
                     callback?(false)
                     
                     print("错误信息:%@", msg as Any)
-                    let alert = NSAlert()
-                    alert.messageText = NSLocalizedString(msg!, comment: "")
-                    alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                    let response = alert.runModal()
-                    if response == .alertFirstButtonReturn {
-                        if(resultDict.code == 317) {
-                            self.signUpState = .verificationCode
-                            self.countDown(type: .login, callback: nil)
-                        } else {
-                            
+                    DispatchQueue.main.async {
+                        let alert = NSAlert()
+                        alert.messageText = NSLocalizedString(msg!, comment: "")
+                        alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                        let response = alert.runModal()
+                        if response == .alertFirstButtonReturn {
+                            if(resultDict.code == 317) {
+                                self.signUpState = .verificationCode
+                                self.countDown(type: .login, callback: nil)
+                            } else {
+                                
+                            }
                         }
                     }
                 }