Bläddra i källkod

add message in case configuration fails / only skip configuration upon startup if it succeeded in app run before

Jonas Reinsch 6 år sedan
förälder
incheckning
265f1cd2e6
2 ändrade filer med 16 tillägg och 6 borttagningar
  1. 13 2
      deltachat-ios/AppCoordinator.swift
  2. 3 4
      deltachat-ios/AppDelegate.swift

+ 13 - 2
deltachat-ios/AppCoordinator.swift

@@ -33,11 +33,22 @@ class AppCoordinator: Coordinator {
         }
     }
     
-    func displayCredentialsController() {
+    func displayCredentialsController(message: String? = nil) {
         let credentialsController = CredentialsController()
         let credentialsNav = UINavigationController(rootViewController: credentialsController)
         
-        baseController.present(credentialsNav, animated: false, completion: nil)
+        if baseController.presentedViewController != nil {
+            baseController.dismiss(animated: false, completion: nil)
+        }
+        
+        baseController.present(credentialsNav, animated: false) {
+            if let message = message {
+                let alert = UIAlertController(title: "Warning", message: message, preferredStyle: .alert)
+                alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
+                credentialsNav.present(alert, animated: false, completion: nil)
+                
+            }
+        }
     }
     
     func setupInnerViewControllers() {

+ 3 - 4
deltachat-ios/AppDelegate.swift

@@ -48,10 +48,12 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
             AppDelegate.progress = progressInPromille / 1000
             print("progress: \(AppDelegate.progress)")
             if data1 == 1000 {
+                UserDefaults.standard.set(true, forKey: Constants.Keys.deltachatUserProvidedCredentialsKey)
+                UserDefaults.standard.synchronize()
                 AppDelegate.appCoordinator.setupInnerViewControllers()
             }
             if data1 == 0 {
-                AppDelegate.appCoordinator.displayCredentialsController()
+                AppDelegate.appCoordinator.displayCredentialsController(message: "Configuration failed. Make sure to enter correct credentials. If using GMail, enable access for 'less secure apps' first.")
             }
             let nc = NotificationCenter.default
             
@@ -150,9 +152,6 @@ func initCore(withCredentials: Bool, email: String = "", password: String = "")
         }
         dc_set_config(mailboxPointer, "addr", email)
         dc_set_config(mailboxPointer, "mail_pw", password)
-
-        UserDefaults.standard.set(true, forKey: Constants.Keys.deltachatUserProvidedCredentialsKey)
-        UserDefaults.standard.synchronize()
         
         // TODO: - handle failure, need to show credentials screen again
         dc_configure(mailboxPointer)