Skip to content

armgit / core

Public Imported from GitHub
0

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

Added fixes for iOS and provider initialization in general

Michael Rademaker5ade96fae69d
diff --git a/console/android/src/main/java/org/openremote/android/MainActivity.java b/console/android/src/main/java/org/openremote/android/MainActivity.java
index 1f78cfa0d..43ae4d6e7 100644
--- a/console/android/src/main/java/org/openremote/android/MainActivity.java
+++ b/console/android/src/main/java/org/openremote/android/MainActivity.java
@@ -185,7 +185,7 @@ public class MainActivity extends Activity {
protected void openIntentUrl(Intent intent) {
if (!intent.hasExtra("appUrl")) {
String url = getClientUrl();
- LOG.fine("Loading web view: " + url);
+ LOG.fine("Loading web view: " + url);
loadUrl(url);
} else {
String url = getClientUrl();
diff --git a/console/iOS/ORLib/ORLib/Constants.swift b/console/iOS/ORLib/ORLib/Constants.swift
index 8a4703600..43c524ed0 100644
--- a/console/iOS/ORLib/ORLib/Constants.swift
+++ b/console/iOS/ORLib/ORLib/Constants.swift
@@ -39,6 +39,7 @@ public enum DefaultsKey {
public static let successKey = "success"
public static let dataKey = "data"
public static let enabledKey = "enabled"
+ public static let disabledKey = "disabled"
}
public enum Actions {
diff --git a/console/iOS/ORLib/ORLib/ErrorManager.swift b/console/iOS/ORLib/ORLib/ErrorManager.swift
index b02b18691..25718461f 100644
--- a/console/iOS/ORLib/ORLib/ErrorManager.swift
+++ b/console/iOS/ORLib/ORLib/ErrorManager.swift
@@ -28,8 +28,8 @@ public class ErrorManager : NSObject {
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)
+ topWindow.windowLevel = UIWindow.Level.alert + 1
+ let alertVC = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: UIAlertController.Style.alert)
let alertAction = UIAlertAction(title: "Done", style: .cancel) { (action) in
topWindow.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
topWindow.isHidden = true
diff --git a/console/iOS/ORLib/ORLib/GeofenceProvider.swift b/console/iOS/ORLib/ORLib/GeofenceProvider.swift
index 4e897ef71..e329685d3 100644
--- a/console/iOS/ORLib/ORLib/GeofenceProvider.swift
+++ b/console/iOS/ORLib/ORLib/GeofenceProvider.swift
@@ -6,9 +6,10 @@ public class GeofenceProvider: NSObject, URLSessionDelegate {
static let baseUrlKey = "baseUrl"
static let consoleIdKey = "consoleId"
static let geoPostUrlsKey = "geoPostUrls"
+ static let geoDisabledKey = "geoDisabled"
let version = "ORConsole"
- let geofenceFetchEndpoint = "api/rules/geofences/"
+ let geofenceFetchEndpoint = "rules/geofences/"
let locationManager = CLLocationManager()
let userdefaults = UserDefaults(suiteName: ORAppGroup.entitlement)
var geoPostUrls = [String:[String]]()
@@ -40,7 +41,8 @@ public class GeofenceProvider: NSObject, URLSessionDelegate {
DefaultsKey.requiresPermissionKey: true,
DefaultsKey.hasPermissionKey: checkPermission(),
DefaultsKey.successKey: true,
- DefaultsKey.enabledKey: false
+ DefaultsKey.enabledKey: false,
+ DefaultsKey.disabledKey: userdefaults?.bool(forKey: GeofenceProvider.geoDisabledKey) ?? false
]
}
@@ -90,6 +92,7 @@ public class GeofenceProvider: NSObject, URLSessionDelegate {
self.consoleId = consoleId
userdefaults?.set(self.baseURL, forKey: GeofenceProvider.baseUrlKey)
userdefaults?.set(self.consoleId, forKey: GeofenceProvider.consoleIdKey)
+ userdefaults?.removeObject(forKey: GeofenceProvider.geoDisabledKey)
userdefaults?.synchronize()
enableCallback = callback
if checkPermission() {
@@ -116,6 +119,10 @@ public class GeofenceProvider: NSObject, URLSessionDelegate {
public func disable()-> [String: Any] {
locationManager.stopMonitoringSignificantLocationChanges()
+ userdefaults?.set(true, forKey: GeofenceProvider.geoDisabledKey)
+ userdefaults?.removeObject(forKey: GeofenceProvider.baseUrlKey)
+ userdefaults?.removeObject(forKey: GeofenceProvider.consoleIdKey)
+ userdefaults?.synchronize()
return [
DefaultsKey.actionKey: Actions.providerDisable,
DefaultsKey.providerKey: Providers.geofence
diff --git a/console/iOS/ORLib/ORLib/ORAppDelegate.swift b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
index 06c52f57f..236765c09 100644
--- a/console/iOS/ORLib/ORLib/ORAppDelegate.swift
+++ b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
@@ -36,7 +36,7 @@ open class ORAppDelegate: UIResponder, UIApplicationDelegate, URLSessionDelegate
private var geofenceProvider : GeofenceProvider?
- open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+ open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
// if the app was launched because of geofencing
@@ -46,14 +46,14 @@ open class ORAppDelegate: UIResponder, UIApplicationDelegate, URLSessionDelegate
let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)
freopen(logFilePath.cString(using: String.Encoding.ascii)!, "a+", stderr)
- if launchOptions?[UIApplicationLaunchOptionsKey.location] != nil {
+ if launchOptions?[UIApplication.LaunchOptionsKey.location] != nil {
NSLog("%@", "App started from location update")
// create new GeofenceProvider which creates a CLLocationManager that will receive the location update
geofenceProvider = GeofenceProvider()
if CLLocationManager.authorizationStatus() == .authorizedAlways {
geofenceProvider?.locationManager.startMonitoringSignificantLocationChanges()
}
- } else if let remoteNotifcation = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {
+ } else if let remoteNotifcation = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {
NSLog("%@", "App started from remote notification")
if let action = remoteNotifcation[DefaultsKey.actionKey] as? String {
if action == Actions.geofenceRefresh {
@@ -186,7 +186,7 @@ open class ORAppDelegate: UIResponder, UIApplicationDelegate, URLSessionDelegate
if (!reachabilityAlertShown) {
let topWindow = UIWindow(frame: UIScreen.main.bounds)
topWindow.rootViewController = UIViewController()
- topWindow.windowLevel = UIWindowLevelAlert + 1
+ topWindow.windowLevel = UIWindow.Level.alert + 1
reachabilityAlert = UIAlertController(title: "Network Error", message: "Your device seems to be offline", preferredStyle: .alert)
let reachabilityRetryAction = UIAlertAction(title: "Retry", style: .default, handler: { (action) in
diff --git a/console/iOS/ORLib/ORLib/ORViewController.swift b/console/iOS/ORLib/ORLib/ORViewController.swift
index 638c5b2ff..32df39d3d 100644
--- a/console/iOS/ORLib/ORLib/ORViewController.swift
+++ b/console/iOS/ORLib/ORLib/ORViewController.swift
@@ -65,7 +65,7 @@ open class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMess
})
}
} else if action == Actions.providerDisable {
- if let disableData = pushProvider?.disbale() {
+ if let disableData = pushProvider?.disable() {
sendData(data: disableData)
}
}
@@ -78,7 +78,7 @@ open class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMess
if let consoleId = postMessageDict[GeofenceProvider.consoleIdKey] as? String {
geofenceProvider?.enable(baseUrl: "\(ORServer.baseUrl)api/\(ORServer.realm)", consoleId: consoleId, callback: { enableData in
self.sendData(data: enableData)
- DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
+ DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
self.geofenceProvider?.fetchGeofences()
}
})
@@ -155,7 +155,7 @@ open class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMess
let app = UIApplication.shared
if navigationAction.targetFrame == nil, let url = navigationAction.request.url{
if app.canOpenURL(url) {
- app.open(url, options: [:], completionHandler: nil)
+ app.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
decisionHandler(.cancel)
}
} else {
@@ -323,3 +323,8 @@ open class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMess
}
}
}
+
+// Helper function inserted by Swift 4.2 migrator.
+fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
+ return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
+}
diff --git a/console/iOS/ORLib/ORLib/PushNotificationProvider.swift b/console/iOS/ORLib/ORLib/PushNotificationProvider.swift
index c1c228e17..30a437c78 100644
--- a/console/iOS/ORLib/ORLib/PushNotificationProvider.swift
+++ b/console/iOS/ORLib/ORLib/PushNotificationProvider.swift
@@ -14,6 +14,7 @@ public class PushNotificationProvider: NSObject {
let userdefaults = UserDefaults(suiteName: ORAppGroup.entitlement)
let version = "fcm"
public var consoleId: String = ""
+ static let pushDisabledKey = "pushDisabled"
public override init() {
super.init()
@@ -31,7 +32,8 @@ public class PushNotificationProvider: NSObject {
DefaultsKey.hasPermissionKey: true,
DefaultsKey.requiresPermissionKey: true,
DefaultsKey.successKey: true,
- DefaultsKey.enabledKey: false
+ DefaultsKey.enabledKey: false,
+ DefaultsKey.disabledKey: self.userdefaults?.bool(forKey: PushNotificationProvider.pushDisabledKey) ?? false
])
case .denied:
@@ -42,10 +44,11 @@ public class PushNotificationProvider: NSObject {
DefaultsKey.hasPermissionKey: false,
DefaultsKey.requiresPermissionKey: true,
DefaultsKey.successKey: true,
- DefaultsKey.enabledKey: false
+ DefaultsKey.enabledKey: false,
+ DefaultsKey.disabledKey: self.userdefaults?.bool(forKey: PushNotificationProvider.pushDisabledKey) ?? false
])
- case .notDetermined:
+ default:
callback( [
DefaultsKey.actionKey: Actions.providerInit,
DefaultsKey.providerKey: Providers.push,
@@ -53,7 +56,8 @@ public class PushNotificationProvider: NSObject {
DefaultsKey.hasPermissionKey: nil,
DefaultsKey.requiresPermissionKey: true,
DefaultsKey.successKey: true,
- DefaultsKey.enabledKey: false
+ DefaultsKey.enabledKey: false,
+ DefaultsKey.disabledKey: self.userdefaults?.bool(forKey: PushNotificationProvider.pushDisabledKey) ?? false
])
}
}
@@ -62,6 +66,7 @@ public class PushNotificationProvider: NSObject {
public func enable(consoleId: String, callback:@escaping ([String: Any]) ->(Void)) {
self.consoleId = consoleId
userdefaults?.set(self.consoleId, forKey: GeofenceProvider.consoleIdKey)
+ userdefaults?.removeObject(forKey: PushNotificationProvider.pushDisabledKey)
userdefaults?.synchronize()
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
@@ -87,7 +92,7 @@ public class PushNotificationProvider: NSObject {
DefaultsKey.dataKey: ["token": self.userdefaults?.string(forKey: DefaultsKey.fcmTokenKey)]
])
- case .notDetermined:
+ default:
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .badge, .sound],
completionHandler: {granted, _ in
@@ -110,7 +115,9 @@ public class PushNotificationProvider: NSObject {
}
}
- public func disbale()-> [String: Any] {
+ public func disable()-> [String: Any] {
+ userdefaults?.set(true, forKey: PushNotificationProvider.pushDisabledKey)
+ userdefaults?.synchronize()
return [
DefaultsKey.actionKey: Actions.providerDisable,
DefaultsKey.providerKey: Providers.push
diff --git a/ui/component/core/src/console.ts b/ui/component/core/src/console.ts
index f0f77a138..1c6f2f94e 100644
--- a/ui/component/core/src/console.ts
+++ b/ui/component/core/src/console.ts
@@ -163,17 +163,17 @@ export class Console {
this._initialiseInProgress = true;
try {
- // Get an ID for this console if it doesn't have one
- if (!this._registration.id) {
- await this.sendRegistration(0);
- }
-
if (this._registration.providers) {
for (let providerName of Object.keys(this._registration.providers)) {
await this._initialiseProvider(providerName);
}
}
+ // Get an ID for this console if it doesn't have one
+ if (!this._registration.id) {
+ await this.sendRegistration(0);
+ }
+
this._initialised = true;
this._initialiseInProgress = false;
@@ -226,6 +226,7 @@ export class Console {
this._registration.providers![providerName].hasPermission = response.hasPermission;
this._registration.providers![providerName].success = response.success;
this._registration.providers![providerName].enabled = response.success;
+ this._registration.providers![providerName].data = response.data;
let index = this._pendingProviderEnables.indexOf(providerName);
@@ -513,6 +514,7 @@ export class Console {
this._registration.providers![providerName].success = initResponse.success;
this._registration.providers![providerName].enabled = initResponse.enabled;
this._registration.providers![providerName].disabled = initResponse.disabled;
+ this._registration.providers![providerName].data = initResponse.data;
if (!initResponse.success) {
console.debug("Provider initialisation failed: '" + providerName + "'");
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index 84af225d2..5a1447076 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -184,7 +184,7 @@ export class OrMap extends LitElement {
stylesArr.forEach((styleItem) => {
const styleElem = document.createElement("style");
- styleElem.textContent = styleItem.toString();
+ styleElem.textContent = String(styleItem.toString());
if (this._mapContainer!.children.length > 0) {
this._mapContainer!.insertBefore(styleElem, this._mapContainer!.children[0]);
} else {