Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

iOS console : added network activity indicator

William Balcaen6c64e3aeca52
diff --git a/console/iOS/console/AppDelegate.swift b/console/iOS/console/AppDelegate.swift
index ee5215cc0..bdc9cd12a 100644
--- a/console/iOS/console/AppDelegate.swift
+++ b/console/iOS/console/AppDelegate.swift
@@ -19,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var reachabilityAlert : UIAlertController?
var reachabilityAlertShown = false
let internetReachability = Reachability.forInternetConnection()
+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
@@ -109,6 +110,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var assetId : String = ""
var attributeName : String = ""
var rawJson : String = ""
+ UIApplication.shared.isNetworkActivityIndicatorVisible = true
switch response.actionIdentifier {
case ActionType.ACTION_DEEP_LINK :
// open url
@@ -133,6 +135,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
TokenManager.sharedInstance.getAccessToken { (accessTokenResult) in
switch accessTokenResult {
case .Failure(let error) :
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
ErrorManager.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, UNUserNotificationCenterD
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
DispatchQueue.main.async {
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
if (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.swift
index 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 = true
TokenManager.sharedInstance.getAccessToken { (accessTokenResult) in
switch accessTokenResult {
case .Failure(let error) :
@@ -65,6 +66,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue : nil)
let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
DispatchQueue.main.async {
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
if (error != nil) {
NSLog("error %@", (error! as NSError).localizedDescription)
let error = NSError(domain: "", code: 0, userInfo: [
@@ -84,11 +86,13 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa
func 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 = false
ErrorManager.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 = true
TokenManager.sharedInstance.getAccessToken { (accessTokenResult) in
switch accessTokenResult {
case .Failure(let error) :
@@ -165,6 +174,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue : nil)
let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
DispatchQueue.main.async {
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
if (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.swift
index 1fd411ee1..16babff87 100644
--- a/console/iOS/console/TokenManager.swift
+++ b/console/iOS/console/TokenManager.swift
@@ -48,6 +48,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationD
func authenticate() {
NSLog("authenticate")
+ UIApplication.shared.isNetworkActivityIndicatorVisible = true
let 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 = false
self.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, WKNavigationD
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
NSLog("error %@", error.localizedDescription)
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
ErrorManager.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, WKNavigationD
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
let errorCode = (error as NSError).code
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
if errorCode != NSURLErrorCancelled {
NSLog("error %@", error.localizedDescription)
ErrorManager.showError(error: NSError(domain: "navigationError", code: 0, userInfo:[
@@ -180,6 +184,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationD
func sendDeviceId() {
print("Device Id : -------------> ",deviceId ?? "")
+ UIApplication.shared.isNetworkActivityIndicatorVisible = true
self.getAccessToken { (accessTokenResult) in
switch accessTokenResult {
case .Failure(let error) :
@@ -196,6 +201,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationD
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
DispatchQueue.main.async {
+ UIApplication.shared.isNetworkActivityIndicatorVisible = false
if (error != nil) {
NSLog("error %@", (error! as NSError).localizedDescription)
let error = NSError(domain: "", code: 0, userInfo: [