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 errorManager, left only one shared Constant file shared between app and app extension
William Balcaen368af295b230
diff --git a/console/iOS/NotificationExtension/Constants.swift b/console/iOS/NotificationExtension/Constants.swiftdeleted file mode 100644index c23c16d07..000000000--- a/console/iOS/NotificationExtension/Constants.swift+++ /dev/null@@ -1,31 +0,0 @@-//-// Constants.swift-// console-//-// Created by William Balcaen on 28/03/17.-// Copyright © 2017 TInSys. All rights reserved.-//--import Foundation--struct DefaultsKey {- static let offlineToken = "offlineToken"- static let refreshToken = "refreshToken"- static let idToken = "idToken"-}--struct AppGroup {- static let entitlement = "group.org.openremote.console"-}--enum Server {- static let hostURL = "192.168.0.177"- static let initialPath = String(format:"console/%@/",Server.realm)- static let realm = "blok61"- static let apiTestResource = String(format:"https://%@/%@/notification/alert",Server.hostURL,Server.realm)-}--enum ActionType {- static let ACTION_DEEP_LINK = "ACTION_DEEP_LINK"- static let ACTION_ACTUATOR = "ACTION_ACTUATOR"-}diff --git a/console/iOS/console.xcodeproj/project.pbxproj b/console/iOS/console.xcodeproj/project.pbxprojindex e3f75a4a3..1acb16b6b 100644--- a/console/iOS/console.xcodeproj/project.pbxproj+++ b/console/iOS/console.xcodeproj/project.pbxproj@@ -7,6 +7,9 @@objects = {/* Begin PBXBuildFile section */+ 06B097EA1EA902CF00DF5C43 /* ErrorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B097E91EA902CF00DF5C43 /* ErrorManager.swift */; };+ 06B097EB1EA902CF00DF5C43 /* ErrorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B097E91EA902CF00DF5C43 /* ErrorManager.swift */; };+ 06B097EC1EA902D900DF5C43 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2D48301E560B7500C95665 /* Constants.swift */; };87A2313B4335644906A6C5DB /* Pods_console.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D4964874264350BC5EAC8F84 /* Pods_console.framework */; };FA1D73E21E53374E00F6240A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1D73E11E53374E00F6240A /* AppDelegate.swift */; };FA1D73E41E53374E00F6240A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1D73E31E53374E00F6240A /* ViewController.swift */; };@@ -15,7 +18,6 @@FA1D73EC1E53374E00F6240A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA1D73EA1E53374E00F6240A /* LaunchScreen.storyboard */; };FA1D73F61E53392F00F6240A /* ORViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1D73F51E53392F00F6240A /* ORViewController.swift */; };FA2D48311E560B7500C95665 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2D48301E560B7500C95665 /* Constants.swift */; };- FA3297AB1E8A4FC6008B77D3 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA3297AA1E8A4FC6008B77D3 /* Constants.swift */; };FAA226B81E71563F009A8FEC /* TokenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226B71E71563F009A8FEC /* TokenManager.swift */; };FAA226BA1E715ED6009A8FEC /* TokenManagerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */; };FAA226BC1E7163D9009A8FEC /* TokenManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */; };@@ -49,6 +51,7 @@/* End PBXCopyFilesBuildPhase section *//* Begin PBXFileReference section */+ 06B097E91EA902CF00DF5C43 /* ErrorManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorManager.swift; sourceTree = "<group>"; };146098EE6A2181297FD32B8D /* Pods-console.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-console.debug.xcconfig"; path = "Pods/Target Support Files/Pods-console/Pods-console.debug.xcconfig"; sourceTree = "<group>"; };6A25CEFE37281B00C9BA7EB5 /* Pods-console.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-console.release.xcconfig"; path = "Pods/Target Support Files/Pods-console/Pods-console.release.xcconfig"; sourceTree = "<group>"; };D4964874264350BC5EAC8F84 /* Pods_console.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_console.framework; sourceTree = BUILT_PRODUCTS_DIR; };@@ -62,7 +65,6 @@FA1D73F51E53392F00F6240A /* ORViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ORViewController.swift; sourceTree = "<group>"; };FA2D48301E560B7500C95665 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };FA3297A91E8A4AE5008B77D3 /* NotificationExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationExtension.entitlements; sourceTree = "<group>"; };- FA3297AA1E8A4FC6008B77D3 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };FAA226B71E71563F009A8FEC /* TokenManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenManager.swift; sourceTree = "<group>"; };FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TokenManagerView.xib; sourceTree = "<group>"; };FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenManagerViewController.swift; sourceTree = "<group>"; };@@ -155,6 +157,7 @@FA2D48291E55D9F600C95665 /* utils */ = {isa = PBXGroup;children = (+ 06B097E91EA902CF00DF5C43 /* ErrorManager.swift */,FABC54E61E7AEBD300B7B718 /* Reachability.h */,FABC54E71E7AEBD300B7B718 /* Reachability.m */,FAA226B71E71563F009A8FEC /* TokenManager.swift */,@@ -171,7 +174,6 @@FA3297A91E8A4AE5008B77D3 /* NotificationExtension.entitlements */,FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */,FAFF2E2E1E7A95120076BDE3 /* Info.plist */,- FA3297AA1E8A4FC6008B77D3 /* Constants.swift */,);path = NotificationExtension;sourceTree = "<group>";@@ -350,6 +352,7 @@files = (FAA226BC1E7163D9009A8FEC /* TokenManagerViewController.swift in Sources */,FA2D48311E560B7500C95665 /* Constants.swift in Sources */,+ 06B097EA1EA902CF00DF5C43 /* ErrorManager.swift in Sources */,FA1D73E41E53374E00F6240A /* ViewController.swift in Sources */,FABC54E81E7AEBD300B7B718 /* Reachability.m in Sources */,FAA226B81E71563F009A8FEC /* TokenManager.swift in Sources */,@@ -362,8 +365,9 @@isa = PBXSourcesBuildPhase;buildActionMask = 2147483647;files = (+ 06B097EB1EA902CF00DF5C43 /* ErrorManager.swift in Sources */,FAFF2E2D1E7A95120076BDE3 /* NotificationService.swift in Sources */,- FA3297AB1E8A4FC6008B77D3 /* Constants.swift in Sources */,+ 06B097EC1EA902D900DF5C43 /* Constants.swift in Sources */,);runOnlyForDeploymentPostprocessing = 0;};diff --git a/console/iOS/console/AppDelegate.swift b/console/iOS/console/AppDelegate.swiftindex 943992506..ee5215cc0 100644--- a/console/iOS/console/AppDelegate.swift+++ b/console/iOS/console/AppDelegate.swift@@ -133,7 +133,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDTokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :- self.showError(error: error!)+ ErrorManager.showError(error: error!)case .Success(let accessToken) :guard let urlRequest = URL(string: String(format:"%@%i", Server.deleteNotifiedAlertResource, alertId as! Int)) else { return }let request = NSMutableURLRequest(url: urlRequest)@@ -151,13 +151,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDlet error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {if let httpStatus = response as? HTTPURLResponse , httpStatus.statusCode != 204 {let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorSendingDeviceId", value: "Could not delete server alert", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {NSLog("Deleted notification alert %i",alertId as! Int)}@@ -256,24 +256,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD}}-- func showError(error : Error) {- NSLog("showing error %@",error as NSError)- let topWindow = UIWindow(frame: UIScreen.main.bounds)- topWindow.rootViewController = UIViewController()- topWindow.windowLevel = UIWindowLevelAlert + 1- let alertVC = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)- let alertAction = UIAlertAction(title: "Done", style: .cancel) { (action) in- topWindow.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)- topWindow.isHidden = true- }-- alertVC.addAction(alertAction)- DispatchQueue.main.async {- topWindow.makeKeyAndVisible()- topWindow.rootViewController?.present(alertVC, animated: true, completion: nil)- }- }}diff --git a/console/iOS/console/ErrorManager.swift b/console/iOS/console/ErrorManager.swiftnew file mode 100644index 000000000..f5cb03eae--- /dev/null+++ b/console/iOS/console/ErrorManager.swift@@ -0,0 +1,34 @@+//+// ErrorManager.swift+// console+//+// Created by William Balcaen on 20/04/2017.+// Copyright © 2017 TInSys. All rights reserved.+//++import Foundation+import UIKit++class ErrorManager : NSObject {++ static func showError(error : Error) {+ DispatchQueue.main.async {+ NSLog("showing error %@",error as NSError)+ let topWindow = UIWindow(frame: UIScreen.main.bounds)+ topWindow.rootViewController = UIViewController()+ topWindow.windowLevel = UIWindowLevelAlert + 1+ let alertVC = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)+ let alertAction = UIAlertAction(title: "Done", style: .cancel) { (action) in+ topWindow.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)+ topWindow.isHidden = true+ }++ alertVC.addAction(alertAction)+ DispatchQueue.main.async {+ topWindow.makeKeyAndVisible()+ topWindow.rootViewController?.present(alertVC, animated: true, completion: nil)+ }+ }++ }+}diff --git a/console/iOS/console/ORViewController.swift b/console/iOS/console/ORViewController.swiftindex 13ad92417..5b1ba4008 100644--- a/console/iOS/console/ORViewController.swift+++ b/console/iOS/console/ORViewController.swift@@ -60,25 +60,12 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa}- func showError(error : Error) {- let alertVC = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)- let alertAction = UIAlertAction(title: "Done", style: .cancel, handler: nil)- let alertActionResetToken = UIAlertAction(title: "Reset Token", style: .destructive) { (action) in- TokenManager.sharedInstance.resetToken()- self.dismiss(animated: true, completion: nil)-- }- alertVC.addAction(alertAction)- alertVC.addAction(alertActionResetToken)- self.present(alertVC, animated: true, completion: nil)- }-// just for testing purpose (ask backend to get list of notifications or send a notification to device)func apiCall() {TokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :- self.showError(error: error!)+ ErrorManager.showError(error: error!)case .Success(let accessToken) :guard let urlRequest = URL(string: String(Server.apiTestResource)) else { return }let request = NSMutableURLRequest(url: urlRequest)@@ -95,7 +82,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHalet error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {print(response.debugDescription)_ = self.myWebView?.load(data!, mimeType: "text/html", characterEncodingName: "utf8", baseURL: URL(string:Server.apiTestResource)!)@@ -114,7 +101,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHafunc webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {NSLog("error %@", error.localizedDescription)- showError(error: NSError(domain: "networkError", code: 0, userInfo:[+ ErrorManager.showError(error: NSError(domain: "networkError", code: 0, userInfo:[NSLocalizedDescriptionKey : NSLocalizedString("FailedLoadingPage", value: "Could not load page", comment: "")]))}@@ -177,7 +164,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHaTokenManager.sharedInstance.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :- self.showError(error: error!)+ ErrorManager.showError(error: error!)case .Success(let accessToken) :guard let urlRequest = URL(string: String(String(format: "https://%@/%@/asset/%@/attribute/%@", Server.hostURL, Server.realm, assetId,attributeName))) else { return }print(urlRequest)@@ -195,7 +182,7 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHalet error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {print(response.debugDescription)}diff --git a/console/iOS/console/TokenManager.swift b/console/iOS/console/TokenManager.swiftindex a3ab4f703..1fd411ee1 100644--- a/console/iOS/console/TokenManager.swift+++ b/console/iOS/console/TokenManager.swift@@ -142,7 +142,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDfunc webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {NSLog("error %@", error.localizedDescription)- showError(error: NSError(domain: "networkError", code: 0, userInfo:[+ ErrorManager.showError(error: NSError(domain: "networkError", code: 0, userInfo:[NSLocalizedDescriptionKey : NSLocalizedString("FailedLoadingPage", value: "Could not load page", comment: "")]))}@@ -162,7 +162,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDlet errorCode = (error as NSError).codeif errorCode != NSURLErrorCancelled {NSLog("error %@", error.localizedDescription)- showError(error: NSError(domain: "navigationError", code: 0, userInfo:[+ ErrorManager.showError(error: NSError(domain: "navigationError", code: 0, userInfo:[NSLocalizedDescriptionKey : NSLocalizedString("navigationError", value: "Could not navigate to page", comment: "")]))}@@ -183,7 +183,7 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDself.getAccessToken { (accessTokenResult) inswitch accessTokenResult {case .Failure(let error) :- self.showError(error: error!)+ ErrorManager.showError(error: error!)case .Success(let accessToken) :guard let urlRequest = URL(string: String(Server.registerDeviceResource)) else { return }let request = NSMutableURLRequest(url: urlRequest)@@ -201,13 +201,13 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationDlet error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {if let httpStatus = response as? HTTPURLResponse , httpStatus.statusCode != 204 {let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("ErrorSendingDeviceId", value: "Could not register your device for notifications", comment: "")])- self.showError(error: error)+ ErrorManager.showError(error: error)} else {NSLog("Device registred with token %@",postString)let notificationName = Notification.Name(NotificationsNames.isdeviceIdSent)@@ -221,24 +221,6 @@ class TokenManager:NSObject, WKScriptMessageHandler, WKUIDelegate, WKNavigationD}}- func showError(error : Error) {- NSLog("showing error %@",error as NSError)- let topWindow = UIWindow(frame: UIScreen.main.bounds)- topWindow.rootViewController = UIViewController()- topWindow.windowLevel = UIWindowLevelAlert + 1- let alertVC = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)- let alertAction = UIAlertAction(title: "Done", style: .cancel) { (action) in- self.viewController.dismiss(animated: true, completion: nil)- topWindow.isHidden = true- }-- alertVC.addAction(alertAction)- DispatchQueue.main.async {- topWindow.makeKeyAndVisible()- topWindow.rootViewController?.present(alertVC, animated: true, completion: nil)- }- }-func getAccessToken(callback: @escaping (AccesTokenResult<String>) -> ()) {guard let tkurlRequest = URL(string: String(format:"https://%@/auth/realms/%@/protocol/openid-connect/token",Server.hostURL,Server.realm)) else { return }let tkRequest = NSMutableURLRequest(url: tkurlRequest)