Skip to content

armgit / core

Public Imported from GitHub
0

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

Fixed problem with multiple buttons/actions

Michael Rademakerb72e36ad6637
diff --git a/console/iOS/ORLib/ORLib.podspec b/console/iOS/ORLib/ORLib.podspec
index e2a999326..0c4a82c59 100644
--- a/console/iOS/ORLib/ORLib.podspec
+++ b/console/iOS/ORLib/ORLib.podspec
@@ -10,7 +10,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.1.3'
+ s.version = '1.1.4'
s.authors = 'OpenRemote'
s.homepage = "http://www.openremote.io"
s.source = { :git => 'https://github.com/openremote/openremote.git', :tag => 'cocoapod' + s.version.to_s }
diff --git a/console/iOS/ORLib/ORLib/ORAppDelegate.swift b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
index cfffd94a6..479a6ee7f 100644
--- a/console/iOS/ORLib/ORLib/ORAppDelegate.swift
+++ b/console/iOS/ORLib/ORLib/ORAppDelegate.swift
@@ -185,48 +185,73 @@ extension ORAppDelegate : UNUserNotificationCenterDelegate {
open func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
- var notificationId : Int64? = nil
- let consoleId = UserDefaults.standard.string(forKey: GeofenceProvider.consoleIdKey)
+ let userInfo = response.notification.request.content.userInfo
+ var notificationId : Int64? = nil
+ let consoleId = UserDefaults.standard.string(forKey: GeofenceProvider.consoleIdKey)
- if let notificationIdString = response.notification.request.content.userInfo[ActionType.notificationId] as? String{
- notificationId = Int64(notificationIdString)
- }
-
- switch response.actionIdentifier {
- case UNNotificationDefaultActionIdentifier,
- "openURLAction" :
- if let notiId = notificationId, let conId = consoleId {
- ORNotificationResource.sharedInstance.notificationAcknowledged(notificationId: notiId, targetId: conId, acknowledgement: "acknowledged")
+ if let notificationIdString = userInfo[ActionType.notificationId] as? String{
+ notificationId = Int64(notificationIdString)
}
- if let urlToOpen = response.notification.request.content.userInfo[ActionType.appUrl] as? String {
- let urlRequest: URL?
- if urlToOpen.hasPrefix("http") || urlToOpen.hasPrefix("https") {
- urlRequest = URL(string:urlToOpen)
- } else {
- urlRequest = URL(string:String(format: "%@://%@/%@%@", ORServer.scheme, ORServer.hostURL, ORServer.navigationPath, urlToOpen))
+ switch response.actionIdentifier {
+ case UNNotificationDefaultActionIdentifier:
+ if let notiId = notificationId, let conId = consoleId {
+ ORNotificationResource.sharedInstance.notificationAcknowledged(notificationId: notiId, targetId: conId, acknowledgement: "acknowledged")
}
- if let request = urlRequest{
- if let openInBrowser = response.notification.request.content.userInfo[ActionType.openInBrowser] as? Bool {
- if openInBrowser {
- UIApplication.shared.open(request)
+
+ if let urlToOpen = userInfo[ActionType.appUrl] as? String {
+ let urlRequest: URL?
+ if urlToOpen.hasPrefix("http") || urlToOpen.hasPrefix("https") {
+ urlRequest = URL(string:urlToOpen)
+ } else {
+ urlRequest = URL(string:String(format: "%@://%@/%@%@", ORServer.scheme, ORServer.hostURL, ORServer.navigationPath, urlToOpen))
+ }
+ if let request = urlRequest{
+ if let openInBrowser = userInfo[ActionType.openInBrowser] as? Bool {
+ if openInBrowser {
+ UIApplication.shared.open(request)
+ } else {
+ (self.window?.rootViewController as! ORViewcontroller).loadURL(url:request)
+ }
} else {
(self.window?.rootViewController as! ORViewcontroller).loadURL(url:request)
}
- } else {
- (self.window?.rootViewController as! ORViewcontroller).loadURL(url:request)
+ }
+ }
+ case UNNotificationDismissActionIdentifier,
+ "declineAction":
+ if let notiId = notificationId, let conId = consoleId {
+ ORNotificationResource.sharedInstance.notificationAcknowledged(notificationId: notiId, targetId: conId, acknowledgement: "dismissed")
+ }
+ default :
+ if let buttonsString = userInfo[DefaultsKey.buttonsKey] as? String {
+ if let buttonsData = buttonsString.data(using: .utf8) {
+ if let buttons = try? JSONDecoder().decode([ORPushNotificationButton].self, from: buttonsData) {
+ for button in buttons {
+ if button.title == response.actionIdentifier {
+ if let action = button.action {
+ let urlRequest: URL?
+ if action.url.hasPrefix("http") || action.url.hasPrefix("https") {
+ urlRequest = URL(string:action.url)
+ } else {
+ urlRequest = URL(string:String(format: "%@://%@/%@%@", ORServer.scheme, ORServer.hostURL, ORServer.navigationPath, action.url))
+ }
+ if let request = urlRequest{
+ if action.openInBrowser{
+ UIApplication.shared.open(request)
+ } else {
+ (self.window?.rootViewController as! ORViewcontroller).loadURL(url:request)
+ }
+ }
+ }
+ }
+ }
+ }
}
}
}
- case UNNotificationDismissActionIdentifier,
- "declineAction":
- if let notiId = notificationId, let conId = consoleId {
- ORNotificationResource.sharedInstance.notificationAcknowledged(notificationId: notiId, targetId: conId, acknowledgement: "dismissed")
- }
- default : break
+ completionHandler()
}
- completionHandler()
- }
}
extension ORAppDelegate : MessagingDelegate {
diff --git a/console/iOS/ORLib/ORLib/ORNotificationService.swift b/console/iOS/ORLib/ORLib/ORNotificationService.swift
index 7d904ebe1..2fa803411 100644
--- a/console/iOS/ORLib/ORLib/ORNotificationService.swift
+++ b/console/iOS/ORLib/ORLib/ORNotificationService.swift
@@ -55,7 +55,6 @@ open class ORNotificationService: UNNotificationServiceExtension, URLSessionDele
UNUserNotificationCenter.current().setNotificationCategories(categories)
}
}
- contentHandler(bestAttemptContent)
}
//Buttons
@@ -68,13 +67,8 @@ open class ORNotificationService: UNNotificationServiceExtension, URLSessionDele
var notificationActions = [UNNotificationAction]()
for button in buttons {
- if let action = button.action {
- bestAttemptContent.userInfo[ActionType.appUrl] = action.url
- bestAttemptContent.userInfo[ActionType.silent] = action.silent
- bestAttemptContent.userInfo[ActionType.openInBrowser] = action.openInBrowser
- bestAttemptContent.userInfo[ActionType.httpMethod] = action.httpMethod ?? "GET"
- bestAttemptContent.userInfo[DefaultsKey.dataKey] = action.data ?? "null"
- notificationActions.append(UNNotificationAction(identifier: "openURLAction", title: button.title, options: UNNotificationActionOptions.foreground))
+ if button.action != nil {
+ notificationActions.append(UNNotificationAction(identifier: button.title, title: button.title, options: UNNotificationActionOptions.foreground))
} else {
notificationActions.append(UNNotificationAction(identifier: "declineAction", title: button.title, options: UNNotificationActionOptions.destructive))
}