Skip to content

armgit / core

Public Imported from GitHub
0

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

Updated cocoapod

Michael Rademakere53a9e2953e4
diff --git a/console/iOS/ORLib/ORLib.podspec b/console/iOS/ORLib/ORLib.podspec
index f01a4e44b..8408d996f 100644
--- a/console/iOS/ORLib/ORLib.podspec
+++ b/console/iOS/ORLib/ORLib.podspec
@@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.name = "ORLib"
s.summary = "The OpenRemote library to create console apps."
s.requires_arc = true
- s.version = '1.0.3'
+ s.version = '1.1.0'
s.authors = 'OpenRemote'
s.homepage = "http://www.openremote.com/community/"
s.source = { :git => 'https://github.com/openremote/openremote.git', :tag => 'cocoapod' + s.version.to_s }
diff --git a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
index 84b15e0e0..addf97a47 100644
--- a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
+++ b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
@@ -7,8 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
- 4C31CE9F20AD80860073FA97 /* GeofenceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */; };
4C4C2FB81FD8044A0071CBDA /* ORNotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */; };
+ 4C77278520BC13E800322CBC /* PushNotificationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C77278320BC13E800322CBC /* PushNotificationProvider.swift */; };
+ 4C77278620BC13E800322CBC /* GeofenceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C77278420BC13E800322CBC /* GeofenceProvider.swift */; };
4C82D73F1FC58ED2009DE853 /* ORLib.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C82D73D1FC58ED2009DE853 /* ORLib.h */; settings = {ATTRIBUTES = (Public, ); }; };
4C82D74A1FC58F4E009DE853 /* ORViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C82D7451FC58F4E009DE853 /* ORViewController.swift */; };
4C82D74B1FC58F4E009DE853 /* ORAppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C82D7461FC58F4E009DE853 /* ORAppDelegate.swift */; };
@@ -22,8 +23,9 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeofenceProvider.swift; sourceTree = "<group>"; };
4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ORNotificationService.swift; sourceTree = "<group>"; };
+ 4C77278320BC13E800322CBC /* PushNotificationProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushNotificationProvider.swift; sourceTree = "<group>"; };
+ 4C77278420BC13E800322CBC /* GeofenceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeofenceProvider.swift; sourceTree = "<group>"; };
4C82D73A1FC58ED2009DE853 /* ORLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ORLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C82D73D1FC58ED2009DE853 /* ORLib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ORLib.h; sourceTree = "<group>"; };
4C82D73E1FC58ED2009DE853 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -52,6 +54,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 4C77278220BC13BA00322CBC /* ConsoleProviders */ = {
+ isa = PBXGroup;
+ children = (
+ 4C77278420BC13E800322CBC /* GeofenceProvider.swift */,
+ 4C77278320BC13E800322CBC /* PushNotificationProvider.swift */,
+ );
+ path = ConsoleProviders;
+ sourceTree = "<group>";
+ };
4C82D7301FC58ED2009DE853 = {
isa = PBXGroup;
children = (
@@ -73,6 +84,7 @@
4C82D73C1FC58ED2009DE853 /* ORLib */ = {
isa = PBXGroup;
children = (
+ 4C77278220BC13BA00322CBC /* ConsoleProviders */,
4C82D7531FC590FB009DE853 /* ErrorManager.swift */,
4C82D7541FC590FB009DE853 /* TokenManager.swift */,
4CBC0D461FD6DDA1000BE8B1 /* Reachability.swift */,
@@ -84,7 +96,6 @@
4C82D73D1FC58ED2009DE853 /* ORLib.h */,
4C82D73E1FC58ED2009DE853 /* Info.plist */,
4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */,
- 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */,
);
path = ORLib;
sourceTree = "<group>";
@@ -146,7 +157,7 @@
4C82D7311FC58ED2009DE853 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0910;
+ LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Open Remote Inc.";
TargetAttributes = {
4C82D7391FC58ED2009DE853 = {
@@ -224,7 +235,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 4C31CE9F20AD80860073FA97 /* GeofenceProvider.swift in Sources */,
+ 4C77278620BC13E800322CBC /* GeofenceProvider.swift in Sources */,
+ 4C77278520BC13E800322CBC /* PushNotificationProvider.swift in Sources */,
4C4C2FB81FD8044A0071CBDA /* ORNotificationService.swift in Sources */,
4C82D7581FC590FB009DE853 /* ErrorManager.swift in Sources */,
4C82D74E1FC58F4E009DE853 /* ORLoginViewController.swift in Sources */,
@@ -254,6 +266,7 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
@@ -261,6 +274,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -314,6 +328,7 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
@@ -321,6 +336,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
diff --git a/console/iOS/ORLib/ORLib.xcodeproj/xcshareddata/xcschemes/ORLib.xcscheme b/console/iOS/ORLib/ORLib.xcodeproj/xcshareddata/xcschemes/ORLib.xcscheme
index 94040077f..643b1dd74 100644
--- a/console/iOS/ORLib/ORLib.xcodeproj/xcshareddata/xcschemes/ORLib.xcscheme
+++ b/console/iOS/ORLib/ORLib.xcodeproj/xcshareddata/xcschemes/ORLib.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0910"
+ LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
@@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
diff --git a/console/iOS/ORLib/ORLib/ConsoleProviders/GeofenceProvider.swift b/console/iOS/ORLib/ORLib/ConsoleProviders/GeofenceProvider.swift
new file mode 100644
index 000000000..15b1dffd9
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/ConsoleProviders/GeofenceProvider.swift
@@ -0,0 +1,222 @@
+import UIKit
+import CoreLocation
+
+public class GeofenceProvider: NSObject, URLSessionDelegate {
+
+ static let baseUrlKey = "baseUrl"
+ static let consoleIdKey = "consoleId"
+ static let geoPostUrlsKey = "geoPostUrls"
+
+ let version = "ORConsole"
+ let geofenceFetchEndpoint = "rules/geofences/"
+ let locationManager = CLLocationManager()
+ let userdefaults = UserDefaults.standard
+ var geoPostUrls = [String:String]()
+ var initializeCallback : (([String: Any]) -> (Void))?
+
+ public var baseURL: String = ""
+ public var consoleId: String = ""
+
+ public override init() {
+ super.init()
+ locationManager.delegate = self
+ self.baseURL = userdefaults.string(forKey: GeofenceProvider.baseUrlKey) ?? ""
+ self.consoleId = userdefaults.string(forKey: GeofenceProvider.consoleIdKey) ?? ""
+ self.geoPostUrls = userdefaults.value(forKey: GeofenceProvider.geoPostUrlsKey) as? [String:String] ?? [String:String]()
+ }
+
+ public func initialize(callback:@escaping ([String: Any]) ->(Void)) {
+ initializeCallback = callback
+ if checkPermission() {
+ initializeCallback?([
+ DefaultsKey.actionKey: Actions.providerInit,
+ DefaultsKey.providerKey: Providers.geofence,
+ DefaultsKey.versionKey: version,
+ DefaultsKey.requiresPermissionKey: true,
+ DefaultsKey.hasPermissionKey: checkPermission(),
+ DefaultsKey.successKey: true
+ ])
+ } else {
+ registerPermissions()
+ }
+ }
+
+ private func checkPermission() -> Bool {
+ if CLLocationManager.locationServicesEnabled() {
+ if CLLocationManager.authorizationStatus() == .authorizedAlways{
+ return true
+ }
+ }
+ return false
+ }
+
+ private func registerPermissions() {
+ locationManager.requestAlwaysAuthorization()
+ }
+
+ public func addGeofence(geofence: GeofenceDefinition) {
+ let region = CLCircularRegion(center: CLLocationCoordinate2DMake(geofence.lat, geofence.lng), radius: geofence.radius, identifier:geofence.id)
+ locationManager.startMonitoring(for: region)
+ geoPostUrls[geofence.id] = geofence.postUrl
+ userdefaults.set(geoPostUrls, forKey: GeofenceProvider.geoPostUrlsKey)
+ userdefaults.synchronize()
+ }
+
+ public func removeGeofence(id: String) {
+ for region in locationManager.monitoredRegions {
+ guard let circularRegion = region as? CLCircularRegion, circularRegion.identifier == id else {continue}
+ locationManager.stopMonitoring(for: circularRegion)
+ geoPostUrls.removeValue(forKey: circularRegion.identifier)
+ userdefaults.set(geoPostUrls, forKey: GeofenceProvider.geoPostUrlsKey)
+ userdefaults.synchronize()
+ break
+ }
+ }
+
+ public func clearAllRegions() {
+ for region in locationManager.monitoredRegions {
+ locationManager.stopMonitoring(for: region)
+ }
+ geoPostUrls = [String:String]()
+ userdefaults.set(geoPostUrls, forKey: GeofenceProvider.geoPostUrlsKey)
+ userdefaults.synchronize()
+ }
+
+ public func enable(baseUrl: String, consoleId: String)-> [String: Any] {
+ self.baseURL = baseUrl
+ self.consoleId = consoleId
+ userdefaults.set(self.baseURL, forKey: GeofenceProvider.baseUrlKey)
+ userdefaults.set(self.consoleId, forKey: GeofenceProvider.consoleIdKey)
+ userdefaults.synchronize()
+
+ return [
+ DefaultsKey.actionKey: Actions.providerEnable,
+ DefaultsKey.providerKey: Providers.geofence,
+ DefaultsKey.hasPermissionKey: checkPermission(),
+ DefaultsKey.successKey: true
+ ]
+ }
+
+ public func disbale()-> [String: Any] {
+ return [
+ DefaultsKey.actionKey: "PROVIDER_DISABLE",
+ DefaultsKey.providerKey: Providers.geofence
+ ]
+ }
+
+ public func refreshGeofences() {
+ fetchGeofences()
+ }
+
+ public func fetchGeofences(callback: (([GeofenceDefinition]) -> ())? = nil) {
+ if let tkurlRequest = URL(string: "\(baseURL)/\(geofenceFetchEndpoint)\(consoleId)") {
+ let tkRequest = NSMutableURLRequest(url: tkurlRequest)
+ tkRequest.httpMethod = "GET"
+ let sessionConfiguration = URLSessionConfiguration.default
+ let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
+ let req = session.dataTask(with: tkRequest as URLRequest, completionHandler: { (data, response, error) in
+ if (data != nil){
+ guard let geofences = try? JSONDecoder().decode([GeofenceDefinition].self, from: data!) else {
+ callback?([])
+ return
+ }
+ self.clearAllRegions()
+ print("Geofences count: \(geofences.count)")
+ for geofence in geofences {
+ self.addGeofence(geofence: geofence)
+ }
+ callback?(geofences)
+ } else {
+ NSLog("error %@", (error! as NSError).localizedDescription)
+ let error = NSError(domain: "", code: 0, userInfo: [
+ NSLocalizedDescriptionKey : NSLocalizedString("NoDataReceived", value: "Did not receive any data", comment: "")
+ ])
+ print(error)
+ callback?([])
+ }
+ })
+ req.resume()
+ } else {
+ callback?([])
+ }
+ }
+
+ private func sendGeofenceRequest(url: URL, data:[String: Any]?) {
+ let request = NSMutableURLRequest(url: url)
+ request.addValue("application/json", forHTTPHeaderField:"Content-Type");
+ request.httpMethod = "POST"
+
+ if (data != nil) {
+ if let postBody = try? JSONSerialization.data(withJSONObject: data!, options: []) {
+ request.httpBody = postBody
+ }
+ }
+
+ let sessionConfiguration = URLSessionConfiguration.default
+ let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
+ let req = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
+ if (data != nil){
+
+ } else {
+ NSLog("error %@", (error! as NSError).localizedDescription)
+ let error = NSError(domain: "", code: 0, userInfo: [
+ NSLocalizedDescriptionKey : NSLocalizedString("NoDataReceived", value: "Did not receive any data", comment: "")
+ ])
+ print(error)
+ }
+ })
+ req.resume()
+ }
+
+ public class GeofenceDefinition: NSObject, Decodable {
+ public var id: String = ""
+ public var lat: Double = 0.0
+ public var lng: Double = 0.0
+ public var radius: Double = 0.0
+ public var postUrl: String = ""
+ }
+}
+
+extension GeofenceProvider: CLLocationManagerDelegate {
+ public func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
+ guard let circularRegion = region as? CLCircularRegion else {return}
+
+ guard let postString = geoPostUrls[circularRegion.identifier] else {
+ return
+ }
+ guard let tkurlRequest = URL(string: "\(baseURL)\(postString)") else { return }
+
+ let postData = [
+ "objectValue" : [
+ "type": "Point",
+ "coordinates": [manager.location?.coordinate.longitude, manager.location?.coordinate.latitude]
+ ]
+ ]
+
+ sendGeofenceRequest(url: tkurlRequest, data: postData)
+ }
+
+ public func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
+ guard let circularRegion = region as? CLCircularRegion else {return}
+
+ guard let postString = geoPostUrls[circularRegion.identifier] else {
+ return
+ }
+ guard let tkurlRequest = URL(string: "\(baseURL)\(postString)") else { return }
+
+ sendGeofenceRequest(url: tkurlRequest, data: nil)
+ }
+
+ public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
+ if status != .notDetermined {
+ initializeCallback?([
+ DefaultsKey.actionKey: Actions.providerInit,
+ DefaultsKey.providerKey: Providers.geofence,
+ DefaultsKey.versionKey: version,
+ DefaultsKey.requiresPermissionKey: true,
+ DefaultsKey.hasPermissionKey: checkPermission(),
+ DefaultsKey.successKey: true
+ ])
+ }
+ }
+}
diff --git a/console/iOS/ORLib/ORLib/ConsoleProviders/PushNotificationProvider.swift b/console/iOS/ORLib/ORLib/ConsoleProviders/PushNotificationProvider.swift
new file mode 100644
index 000000000..4a5756d6b
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/ConsoleProviders/PushNotificationProvider.swift
@@ -0,0 +1,45 @@
+//
+// PushNotificationProvider.swift
+// Eindhoven
+//
+// Created by Michael Rademaker on 25/05/2018.
+// Copyright © 2018 OpenRemote Inc. All rights reserved.
+//
+
+import UIKit
+
+public class PushNotificationProvider: NSObject {
+
+ let version = "fcm"
+
+ public override init() {
+ super.init()
+ }
+
+ public func initialize() -> [String: Any] {
+ return [
+ DefaultsKey.actionKey: Actions.providerInit,
+ DefaultsKey.providerKey: Providers.push,
+ DefaultsKey.versionKey: version,
+ DefaultsKey.requiresPermissionKey: false,
+ DefaultsKey.successKey: true
+ ]
+ }
+
+ public func enable()-> [String: Any] {
+ return [
+ DefaultsKey.actionKey: Actions.providerEnable,
+ DefaultsKey.providerKey: Providers.push,
+ DefaultsKey.hasPermissionKey: true,
+ DefaultsKey.successKey: true,
+ DefaultsKey.dataKey: [DefaultsKey.token: TokenManager.sharedInstance.deviceId]
+ ]
+ }
+
+ public func disbale()-> [String: Any] {
+ return [
+ DefaultsKey.actionKey: Actions.providerDisable,
+ DefaultsKey.providerKey: Providers.push
+ ]
+ }
+}
diff --git a/console/iOS/ORLib/ORLib/Constants.swift b/console/iOS/ORLib/ORLib/Constants.swift
index e2d1be730..d5662c9c6 100644
--- a/console/iOS/ORLib/ORLib/Constants.swift
+++ b/console/iOS/ORLib/ORLib/Constants.swift
@@ -27,10 +27,29 @@ public enum AccesTokenResult<String>
}
public enum DefaultsKey {
- static let token = "token"
- static let refreshToken = "refreshToken"
- static let idToken = "idToken"
- static let deviceId = "deviceToken"
+ public static let token = "token"
+ public static let refreshToken = "refreshToken"
+ public static let idToken = "idToken"
+ public static let deviceId = "deviceToken"
+ public static let actionKey = "action"
+ public static let providerKey = "provider"
+ public static let versionKey = "version"
+ public static let requiresPermissionKey = "requiresPermission"
+ public static let hasPermissionKey = "hasPermission"
+ public static let successKey = "success"
+ public static let dataKey = "data"
+}
+
+public enum Actions {
+ public static let providerInit = "PROVIDER_INIT"
+ public static let providerEnable = "PROVIDER_ENABLE"
+ public static let providerDisable = "PROVIDER_DISABLE"
+ public static let geofenceRefresh = "GEOFENCE_REFRESH"
+}
+
+public enum Providers {
+ public static let push = "push"
+ public static let geofence = "geofence"
}
public enum NotificationsNames {
@@ -46,6 +65,12 @@ public enum Notifications {
}
public enum ActionType {
- static let ACTION_DEEP_LINK = "LINK"
- static let ACTION_ACTUATOR = "ACTUATOR"
+ public static let actions = "actions"
+ public static let aps = "aps"
+ public static let alert = "alert"
+ public static let title = "title"
+ public static let type = "type"
+ public static let appUrl = "appUrl"
+ public static let ACTION_DEEP_LINK = "LINK"
+ public static let ACTION_ACTUATOR = "ACTUATOR"
}
diff --git a/console/iOS/ORLib/ORLib/GeofenceProvider.swift b/console/iOS/ORLib/ORLib/GeofenceProvider.swift
deleted file mode 100644
index bec75d573..000000000
--- a/console/iOS/ORLib/ORLib/GeofenceProvider.swift
+++ /dev/null
@@ -1,99 +0,0 @@
-//
-// GeofenceProvider.swift
-// ORLib
-//
-// Created by Michael Rademaker on 17/05/2018.
-// Copyright © 2018 Open Remote Inc. All rights reserved.
-//
-
-import UIKit
-import CoreLocation
-
-class GeofenceProvider: NSObject {
-
- let providerKey = "geofence"
- let locationManager = CLLocationManager()
-
- public var consoleId: String
-
- public func checkPermission() -> Bool {
- if CLLocationManager.locationServicesEnabled() {
- if CLLocationManager.authorizationStatus() == .authorizedAlways{
- return true
- }
- }
- return false
- }
-
- public func clearAllRegions() {
- for region in locationManager.monitoredRegions {
- locationManager.stopMonitoring(for: region)
- }
- }
-
- public func registerPermissions() {
- locationManager.requestAlwaysAuthorization()
- }
-
- public func addGeofence(geofence: GeofenceDefinition) {
- locationManager.startMonitoring(for: geofence)
- }
-
- public func removeGeofence(id: String) {
- for region in locationManager.monitoredRegions {
- guard let circularRegion = region as? GeofenceDefinition, circularRegion.identifier == id else {continue}
- locationManager.stopMonitoring(for: circularRegion)
- break
- }
- }
-
- public func enable(callback: @escaping (AccesTokenResult<String>) -> ()) {
- guard let tkurlRequest = URL(string: String(format:"\(ORServer.scheme)://%@/auth/realms/%@/protocol/openid-connect/token", ORServer.hostURL, ORServer.realm)) else { return }
- let tkRequest = NSMutableURLRequest(url: tkurlRequest)
- tkRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField:"Content-Type");
- tkRequest.httpMethod = "POST"
-
- let postData = [
- "action":"PROVIDER_ENABLE",
- "provider": providerKey,
- "data": [
- "baseUrl":String(format:"\(ORServer.scheme)://%@/", ORServer.hostURL),
- "consoleId": consoleId
- ]
- ]
-
- tkRequest.httpBody = JSONSerialization.data(withJSONObject: postData, options: [])
- let sessionConfiguration = URLSessionConfiguration.default
- let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
- let req = session.dataTask(with: tkRequest as URLRequest, completionHandler: { (data, response, error) in
- if (data != nil){
-
- } else {
- NSLog("error %@", (error! as NSError).localizedDescription)
- let error = NSError(domain: "", code: 0, userInfo: [
- NSLocalizedDescriptionKey : NSLocalizedString("NoDataReceived", value: "Did not receive any data", comment: "")
- ])
- callback(AccesTokenResult.Failure(error))
- }
- })
- req.resume()
- }
-
- class GeofenceDefinition: CLCircularRegion {
- public let id: String
- public let lat: double
- public let lng: double
- public let radius: int
- public let postUrl: String
- }
-}
-
-extension GeofenceProvider: CLLocationManagerDelegate {
- func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
- guard let geoDefinition = region as? GeofenceDefinition else {
- return
- }
-
-
- }
-}
diff --git a/console/iOS/ORLib/ORLib/ORAppDelegate.swift b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
index 90a035c1e..7259170e0 100644
--- a/console/iOS/ORLib/ORLib/ORAppDelegate.swift
+++ b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
@@ -108,6 +108,39 @@ open class ORAppDelegate: UIResponder, UIApplicationDelegate, URLSessionDelegate
}
open func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
+
+ if let actionsString = userInfo["actions"] as? String {
+ if let actionsData = actionsString.data(using: .utf8){
+ if let actions = try? JSONSerialization.jsonObject(with: actionsData, options: []) as? [[String: String]], actions != nil {
+ if let aps = userInfo["aps"] as? [String: Any] {
+ if let alert = aps["alert"] as? [String: String] {
+ let title = alert["title"]
+ let message = alert["body"]
+
+ let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
+
+ for i in (0..<actions!.count) {
+ let actionTitle = actions![i]["title"]
+ let actionType = actions![i]["type"]
+
+ switch actionType {
+ case ActionType.ACTION_DEEP_LINK :
+ alertController.addAction(UIAlertAction(title: actionTitle, style: .default, handler: { alertAction in
+ if let urlToOpen = actions![i]["appUrl"] {
+ guard let urlRequest = URL(string: urlToOpen) else { return }
+ (self.window?.rootViewController as! ORViewcontroller).loadURL(url: urlRequest)
+ }
+ }))
+
+ default : break
+ }
+ }
+ self.window?.rootViewController?.present(alertController, animated: true, completion: nil)
+ }
+ }
+ }
+ }
+ }
completionHandler(UIBackgroundFetchResult.newData)
}
@@ -235,8 +268,8 @@ extension ORAppDelegate : UNUserNotificationCenterDelegate {
reqDataTask.resume()
}
}
- completionHandler()
}
+ completionHandler()
}
}
diff --git a/console/iOS/ORLib/ORLib/Reachability.swift b/console/iOS/ORLib/ORLib/Reachability.swift
index 6f8e6e266..8022c8371 100644
--- a/console/iOS/ORLib/ORLib/Reachability.swift
+++ b/console/iOS/ORLib/ORLib/Reachability.swift
@@ -133,7 +133,7 @@ public class Reachability {
fileprivate var previousFlags: SCNetworkReachabilityFlags?
fileprivate var isRunningOnDevice: Bool = {
- #if (arch(i386) || arch(x86_64)) && os(iOS)
+ #if targetEnvironment(simulator)
return false
#else
return true
diff --git a/console/iOS/ORLib/ORLib/TokenManager.swift b/console/iOS/ORLib/ORLib/TokenManager.swift
index 10756ca7d..ffacca776 100644
--- a/console/iOS/ORLib/ORLib/TokenManager.swift
+++ b/console/iOS/ORLib/ORLib/TokenManager.swift
@@ -23,15 +23,15 @@ import UIKit
import WebKit
public class TokenManager:NSObject, URLSessionDelegate {
-
+
public var offlineToken : String?
public var refreshToken : String?
public var idToken : String?
public var deviceId : String?
public var hasToken: Bool
-
+
public static let sharedInstance = TokenManager()
-
+
override init() {
let defaults = UserDefaults(suiteName: ORAppGroup.entitlement)
defaults?.synchronize()
@@ -51,31 +51,29 @@ public class TokenManager:NSObject, URLSessionDelegate {
deviceId = defaults?.value(forKey: DefaultsKey.deviceId) as? String
super.init()
}
-
- public func storeTokens(tokenJsonDictionnary : [String : String]?) {
+
+ public func storeTokens(tokenJsonDictionnary : [String : String]?) {
let defaults = UserDefaults(suiteName: ORAppGroup.entitlement)
-
- if (tokenJsonDictionnary?["token"] != nil
- && tokenJsonDictionnary?["refreshToken"] != nil
- && tokenJsonDictionnary?["idToken"] != nil) {
- offlineToken = tokenJsonDictionnary?["token"]! ?? nil
+
+ if (tokenJsonDictionnary?["refreshToken"] != nil) {
+ offlineToken = tokenJsonDictionnary?["token"] ?? nil
refreshToken = tokenJsonDictionnary?["refreshToken"]! ?? nil
- idToken = tokenJsonDictionnary?["idToken"]! ?? nil
+ idToken = tokenJsonDictionnary?["idToken"] ?? nil
defaults?.set(offlineToken, forKey: DefaultsKey.token)
defaults?.set(refreshToken, forKey: DefaultsKey.refreshToken)
defaults?.set(idToken, forKey: DefaultsKey.idToken)
hasToken = true;
-
+
// We just got a token, try to send the FCM token, we might not have been able to talk to backend when we got it initialy
sendDeviceId()
}
}
-
- public func logout() {
+
+ public func logout() {
resetToken()
}
-
- public func resetToken() {
+
+ public func resetToken() {
hasToken = false
offlineToken = nil
refreshToken = nil
@@ -85,20 +83,20 @@ public class TokenManager:NSObject, URLSessionDelegate {
defaults?.removeObject(forKey: DefaultsKey.refreshToken)
defaults?.removeObject(forKey: DefaultsKey.idToken)
}
-
- public func resetTokenAndAuthenticate() {
+
+ public func resetTokenAndAuthenticate() {
resetToken()
// authenticate()
}
-
- public func storeDeviceId(token : String) {
+
+ public func storeDeviceId(token : String) {
let defaults = UserDefaults(suiteName: ORAppGroup.entitlement)
deviceId = token
defaults?.set(token, forKey: DefaultsKey.deviceId)
sendDeviceId()
}
-
- public func sendDeviceId() {
+
+ public func sendDeviceId() {
if (deviceId != nil && hasToken) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
self.getAccessToken { (accessTokenResult) in
@@ -145,14 +143,14 @@ public class TokenManager:NSObject, URLSessionDelegate {
}
}
}
-
- public func getAccessToken(callback: @escaping (AccesTokenResult<String>) -> ()) {
+
+ public func getAccessToken(callback: @escaping (AccesTokenResult<String>) -> ()) {
guard let tkurlRequest = URL(string: String(format:"\(ORServer.scheme)://%@/auth/realms/%@/protocol/openid-connect/token", ORServer.hostURL, ORServer.realm)) else { return }
let tkRequest = NSMutableURLRequest(url: tkurlRequest)
tkRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField:"Content-Type");
tkRequest.httpMethod = "POST"
let postString = String(format:"grant_type=refresh_token&refresh_token=%@&client_id=%@", refreshToken!, ORClient.clientId)
-
+
tkRequest.httpBody = postString.data(using: .utf8)
let sessionConfiguration = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
@@ -199,8 +197,8 @@ public class TokenManager:NSObject, URLSessionDelegate {
})
req.resume()
}
-
- public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
+
+ public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
if challenge.protectionSpace.host == ORServer.hostURL {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))