Skip to content

armgit / core

Public Imported from GitHub
0

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

Added files

Michael Rademakerc7aba92b451f
diff --git a/console/iOS/ORLib/ORLib/ORNotificationResource.swift b/console/iOS/ORLib/ORLib/ORNotificationResource.swift
new file mode 100644
index 000000000..11555a174
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/ORNotificationResource.swift
@@ -0,0 +1,64 @@
+ //
+// ORNotificationResource.swift
+// ORLib
+//
+// Created by Michael Rademaker on 08/08/2018.
+//
+
+import UIKit
+
+public class ORNotificationResource: NSObject, URLSessionDelegate {
+
+ public static let sharedInstance = ORNotificationResource()
+
+ private override init() {
+ super.init()
+ }
+
+ public func notificationDelivered(notificationId : Int64, targetId : String) {
+ guard let urlRequest = URL(string: "\(ORServer.scheme)://\(ORServer.hostURL)/\(ORServer.realm)/notification/\(notificationId)/delivered?targetId=\(targetId)") else { return }
+ let request = NSMutableURLRequest(url: urlRequest)
+ request.httpMethod = "PUT"
+ let sessionConfiguration = URLSessionConfiguration.default
+ 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: [
+ NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")
+ ])
+ ErrorManager.showError(error: error)
+ }
+ }
+ })
+ reqDataTask.resume()
+ }
+
+ public func notificationAcknowledged(notificationId : Int64, targetId : String, acknowledgement: String) {
+ guard let urlRequest = URL(string: "\(ORServer.scheme)://\(ORServer.hostURL)/\(ORServer.realm)/notification/\(notificationId)/acknowledged?targetId=\(targetId)") else { return }
+ let request = NSMutableURLRequest(url: urlRequest)
+ request.httpMethod = "PUT"
+
+ if let json = try? JSONSerialization.data(withJSONObject: ["acknowledgement": acknowledgement], options: []) {
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+ request.httpBody = json
+ }
+ let sessionConfiguration = URLSessionConfiguration.default
+ 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: [
+ NSLocalizedDescriptionKey : NSLocalizedString("ErrorCallingAPI", value: "Could not get data", comment: "")
+ ])
+ ErrorManager.showError(error: error)
+ }
+ }
+ })
+ reqDataTask.resume()
+ }
+}
diff --git a/console/iOS/ORLib/ORLib/ORPushNotificationAction.swift b/console/iOS/ORLib/ORLib/ORPushNotificationAction.swift
new file mode 100644
index 000000000..c173d16b1
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/ORPushNotificationAction.swift
@@ -0,0 +1,16 @@
+//
+// ORPushNotificationAction.swift
+// ORLib
+//
+// Created by Michael Rademaker on 01/08/2018.
+//
+
+import UIKit
+
+public struct ORPushNotificationAction: Decodable {
+ public let url: String
+ public let httpMethod: String?
+ public let data: String?
+ public let silent: Bool
+ public let openInBrowser: Bool
+}
diff --git a/console/iOS/ORLib/ORLib/ORPushNotificationButton.swift b/console/iOS/ORLib/ORLib/ORPushNotificationButton.swift
new file mode 100644
index 000000000..9ebdcc485
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/ORPushNotificationButton.swift
@@ -0,0 +1,13 @@
+//
+// ORPushNotificationButton.swift
+// ORLib
+//
+// Created by Michael Rademaker on 07/08/2018.
+//
+
+import UIKit
+
+public struct ORPushNotificationButton: Decodable {
+ public let title: String
+ public let action: ORPushNotificationAction?
+}