100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
iOS console : added network activity indicator
William Balcaen6c64e3aeca52
diff --git a/console/iOS/console/AppDelegate.swift b/console/iOS/console/AppDelegate.swiftindex ee5215cc0..bdc9cd12a 100644--- a/console/iOS/console/AppDelegate.swift+++ b/console/iOS/console/AppDelegate.swift@@ -19,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDvar reachabilityAlert : UIAlertController?var reachabilityAlertShown = falselet internetReachability = Reachability.forInternetConnection()+func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {@@ -109,6 +110,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDvar assetId : String = ""var attributeName : String = ""var rawJson : String = ""+ UIApplication.shared.isNetworkActivityIndicatorVisible = trueswitch response.actionIdentifier {case ActionType.ACTION_DEEP_LINK :// open url@@ -133,6 +135,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDTokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseErrorManager.showError(error: error!)case .Success(let accessToken) :guard let urlRequest = URL(string: String(format:"%@%i", Server.deleteNotifiedAlertResource, alertId as! Int)) else { return }@@ -146,6 +149,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDlet session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) inDispatchQueue.main.async {+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseif (error != nil) {NSLog("error %@", (error! as NSError).localizedDescription)let error = NSError(domain: "", code: 0, userInfo: [diff --git a/console/iOS/console/ORViewController.swift b/console/iOS/console/ORViewController.swiftindex fca25986d..0f8dda749 100644--- a/console/iOS/console/ORViewController.swift+++ b/console/iOS/console/ORViewController.swift@@ -50,6 +50,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa// just for testing purpose (ask backend to get list of notifications or send a notification to device)func apiCall() {+ UIApplication.shared.isNetworkActivityIndicatorVisible = trueTokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :@@ -65,6 +66,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHalet session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue : nil)let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) inDispatchQueue.main.async {+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseif (error != nil) {NSLog("error %@", (error! as NSError).localizedDescription)let error = NSError(domain: "", code: 0, userInfo: [@@ -84,11 +86,13 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHafunc login() {guard let request = URL(string: String(format:"https://%@/%@",Server.hostURL,Server.initialPath)) else { return }+ UIApplication.shared.isNetworkActivityIndicatorVisible = true_ = self.myWebView?.load(URLRequest(url: request))}func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {NSLog("error %@", error.localizedDescription)+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseErrorManager.showError(error: NSError(domain: "networkError", code: 0, userInfo:[NSLocalizedDescriptionKey : NSLocalizedString("FailedLoadingPage", value: "Could not load page", comment: "")]))@@ -105,6 +109,9 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa}}+ func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {+ UIApplication.shared.isNetworkActivityIndicatorVisible = false+ }func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {if challenge.protectionSpace.host == Server.hostURL {@@ -145,10 +152,12 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa}func loadURL(url : URL) {+ UIApplication.shared.isNetworkActivityIndicatorVisible = true_ = self.myWebView?.load(URLRequest(url:url))}func updateAssetAttribute(assetId : String, attributeName : String, rawJson : String) {+ UIApplication.shared.isNetworkActivityIndicatorVisible = trueTokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :@@ -165,6 +174,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHalet session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue : nil)let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) inDispatchQueue.main.async {+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseif (error != nil) {NSLog("error %@", (error! as NSError).localizedDescription)let error = NSError(domain: "", code: 0, userInfo: [diff --git a/console/iOS/console/TokenManager.swift b/console/iOS/console/TokenManager.swiftindex 1fd411ee1..16babff87 100644--- a/console/iOS/console/TokenManager.swift+++ b/console/iOS/console/TokenManager.swift@@ -48,6 +48,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDfunc authenticate() {NSLog("authenticate")+ UIApplication.shared.isNetworkActivityIndicatorVisible = truelet defaults = UserDefaults(suiteName: AppGroup.entitlement)let webCfg:WKWebViewConfiguration = WKWebViewConfiguration()if (!didLogOut) {@@ -123,6 +124,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationD}if (offlineToken != nil && refreshToken != nil && idToken != nil && !didLogOut) {self.hasToken = true+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseself.viewController.dismiss(animated: true, completion: {let notificationName = Notification.Name(NotificationsNames.isAuthenticated)NotificationCenter.default.post(name: notificationName, object: nil)@@ -142,6 +144,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDfunc webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {NSLog("error %@", error.localizedDescription)+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseErrorManager.showError(error: NSError(domain: "networkError", code: 0, userInfo:[NSLocalizedDescriptionKey : NSLocalizedString("FailedLoadingPage", value: "Could not load page", comment: "")]))@@ -160,6 +163,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDfunc webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {let errorCode = (error as NSError).code+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseif errorCode != NSURLErrorCancelled {NSLog("error %@", error.localizedDescription)ErrorManager.showError(error: NSError(domain: "navigationError", code: 0, userInfo:[@@ -180,6 +184,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDfunc sendDeviceId() {print("Device Id : -------------> ",deviceId ?? "")+ UIApplication.shared.isNetworkActivityIndicatorVisible = trueself.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :@@ -196,6 +201,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDlet session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) inDispatchQueue.main.async {+ UIApplication.shared.isNetworkActivityIndicatorVisible = falseif (error != nil) {NSLog("error %@", (error! as NSError).localizedDescription)let error = NSError(domain: "", code: 0, userInfo: [