marinofaggiana 5 years ago
parent
commit
806dfd9937
2 changed files with 26 additions and 31 deletions
  1. 17 17
      iOSClient/Login/CCLogin.m
  2. 9 14
      iOSClient/Login/NCLoginWeb.swift

+ 17 - 17
iOSClient/Login/CCLogin.m

@@ -27,7 +27,7 @@
 #import "NCBridgeSwift.h"
 #import "NCNetworkingEndToEnd.h"
 
-@interface CCLogin () <NCLoginWebDelegate, NCLoginQRCodeDelegate>
+@interface CCLogin () <NCLoginQRCodeDelegate>
 {
     AppDelegate *appDelegate;
     UIView *rootView;
@@ -36,6 +36,20 @@
 
 @implementation CCLogin
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Init =====
+#pragma --------------------------------------------------------------------------------------------
+
+-  (id)initWithCoder:(NSCoder *)aDecoder
+{
+    if (self = [super initWithCoder:aDecoder])  {
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissCCLogin) name:@"dismissCCLogin" object:nil];
+    }
+    
+    return self;
+}
+
 - (void)viewDidLoad
 {
     [super viewDidLoad];
@@ -119,15 +133,6 @@
     }
 }
 
-- (void)viewWillAppear:(BOOL)animated
-{
-    [super viewWillAppear:animated];
-
-    // verify URL
-    if ([self.baseUrl.text length] > 0)
-        [self testUrl];
-}
-
 // E' apparsa
 - (void)viewDidAppear:(BOOL)animated
 {
@@ -181,7 +186,6 @@
             if (_user.hidden && _password.hidden && versionMajor >= k_flow_version_available) {
                 
                 appDelegate.activeLoginWeb = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"NCLoginWeb"];
-                appDelegate.activeLoginWeb.delegate = self;
                 appDelegate.activeLoginWeb.urlBase = self.baseUrl.text;
                 
                 [self presentViewController:appDelegate.activeLoginWeb animated:YES completion:nil];
@@ -289,13 +293,9 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark === NCLoginWebDelegate ===
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)loginWebDismiss
+- (void)dismissCCLogin
 {
-    [self dismissViewControllerAnimated:YES completion:nil];
+    [self dismissViewControllerAnimated:NO completion:nil];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 9 - 14
iOSClient/Login/NCLoginWeb.swift

@@ -23,17 +23,13 @@
 
 import Foundation
 
-@objc protocol NCLoginWebDelegate: class {
-    @objc optional func loginWebDismiss()
-}
-
 class NCLoginWeb: UIViewController {
     
     var webView: WKWebView?
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
     @objc var urlBase = ""
-    @objc weak var delegate: NCLoginWebDelegate?
+    @objc var buttonExitVisible = true
 
     @IBOutlet weak var buttonExit: UIButton!
 
@@ -57,12 +53,10 @@ class NCLoginWeb: UIViewController {
             urlBase =  urlBase + k_flowEndpoint
         }
         
-        // button exit
-        let listAccount = NCManageDatabase.sharedInstance.getAccounts()
-        if listAccount?.count == 0 {
-            buttonExit.isHidden = true
-        } else {
+        if buttonExitVisible {
             self.view.bringSubviewToFront(buttonExit)
+        } else {
+            buttonExit.isHidden = true
         }
         
         loadWebPage(webView: webView!, url: URL(string: urlBase)!)
@@ -95,8 +89,9 @@ class NCLoginWeb: UIViewController {
     }
     
     @IBAction func touchUpInsideButtonExit(_ sender: UIButton) {
+        
         self.dismiss(animated: true) {
-            self.delegate?.loginWebDismiss?()
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dismissCCLogin"), object: nil, userInfo: nil)
         }
     }
 }
@@ -150,10 +145,10 @@ extension NCLoginWeb: WKNavigationDelegate {
                     appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: token)
                         
                     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "initializeMain"), object: nil, userInfo: nil)
-                        
+                    
                     self.dismiss(animated: true) {
-                        self.delegate?.loginWebDismiss?()
-                    }
+                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dismissCCLogin"), object: nil, userInfo: nil)
+                    } 
                 }
             }
         }