diff --git a/PushSDK.podspec b/PushSDK.podspec
index 718d3b0..ea0e8d7 100644
--- a/PushSDK.podspec
+++ b/PushSDK.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PushSDK"
- s.version = "1.1.3"
+ s.version = "1.1.4"
s.summary = "SDK for sending push messages to iOS devices."
s.homepage = "https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS"
diff --git a/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate b/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate
index 2189892..cda9716 100644
Binary files a/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate and b/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/PushSDK/PushSDKFirebase.swift b/PushSDK/PushSDKFirebase.swift
index c287d15..7794ca3 100644
--- a/PushSDK/PushSDKFirebase.swift
+++ b/PushSDK/PushSDKFirebase.swift
@@ -127,6 +127,7 @@ public class PushSDKFirebase: UIResponder, UIApplicationDelegate {
contentBody: String(parsedMessage.message.body ?? ""),
btnText: String(parsedMessage.message.button?.text ?? ""),
btnURL: String(parsedMessage.message.button?.url ?? ""),
+ is2Way: parsedMessage.message.is2Way ?? false,
userInfo: userInfo)
}
@@ -238,6 +239,7 @@ extension PushSDKFirebase {
contentBody: String(parsedMessage.message.body ?? ""),
btnText: String(parsedMessage.message.button?.text ?? ""),
btnURL: String(parsedMessage.message.button?.url ?? ""),
+ is2Way: parsedMessage.message.is2Way ?? false,
userInfo: fdf ?? [:])
}
diff --git a/PushSDK/core/JsonParser.swift b/PushSDK/core/JsonParser.swift
index 3684805..513a4f4 100644
--- a/PushSDK/core/JsonParser.swift
+++ b/PushSDK/core/JsonParser.swift
@@ -114,7 +114,7 @@ class PushServerAnswParser {
let elem1: ImageResponse = ImageResponse.init(url: parsedJson.message?.image?.url)
let elem2: ButtonResponse = ButtonResponse.init(text: parsedJson.message?.button?.text, url: parsedJson.message?.button?.url)
- let elem3: MessagesResponseStr = MessagesResponseStr.init(phone: parsedJson.message?.phone, messageId: parsedJson.message?.messageId, title: parsedJson.message?.title, body: parsedJson.message?.body, image: elem1, button: elem2, time: parsedJson.message?.time, partner: parsedJson.message?.partner)
+ let elem3: MessagesResponseStr = MessagesResponseStr.init(phone: parsedJson.message?.phone, messageId: parsedJson.message?.messageId, title: parsedJson.message?.title, body: parsedJson.message?.body, image: elem1, button: elem2, time: parsedJson.message?.time, partner: parsedJson.message?.partner, is2Way: parsedJson.message?.is2Way)
let res = FullFirebaseMessageStr.init(aps: MessApsDataStr(contentAvailable: parsedJson.aps?.contentavailable ?? 0),
message: elem3,
@@ -179,6 +179,7 @@ struct PushKMessageListParse: Decodable {
var time: String?=nil
var body: String?=nil
var title: String?=nil
+ var is2Way: Bool?=false
}
struct FullFirebaseMessage: Decodable {
diff --git a/PushSDK/core/Notifications.swift b/PushSDK/core/Notifications.swift
index 861925c..cefa0a4 100644
--- a/PushSDK/core/Notifications.swift
+++ b/PushSDK/core/Notifications.swift
@@ -19,6 +19,7 @@ class PushNotification {
contentBody: String,
btnText: String,
btnURL: String,
+ is2Way: Bool,
userInfo: [AnyHashable: Any]
) {
PushKConstants.logger.debug("makePushNotification input: imageUrl: \(imageUrl), timeInterval: \(timeInterval), contentTitle: \(contentTitle), contentSubtitle: \(contentSubtitle), contentBody: \(contentBody)")
@@ -36,12 +37,18 @@ class PushNotification {
content.subtitle = contentSubtitle
}
content.sound = UNNotificationSound.default
+ content.categoryIdentifier = "pushKActionCategory"
+
+ var isPushActionButton = false
if(btnURL != "" && btnText != ""){
- registerNotificationAction(btnText: btnText)
- content.categoryIdentifier = "pushKActionCategory"
+ isPushActionButton = true
let userInfoAction = userInfo.merging(["pushKActionButtonURL" : btnURL]){(current, _) in current}
content.userInfo = userInfoAction
+ }
+
+ if(isPushActionButton || is2Way){
+ setActions(btnText: btnText, isPushActionButton: isPushActionButton, is2Way: is2Way)
}
@@ -100,18 +107,37 @@ class PushNotification {
})
}
- func registerNotificationAction(btnText: String){
- let acceptAction = UNNotificationAction(identifier: "pushKNotificationActionId",
- title: btnText,
- options: [UNNotificationActionOptions.foreground])
-
- let pushCategory =
- UNNotificationCategory(identifier: "pushKActionCategory",
- actions: [acceptAction],
- intentIdentifiers: [],
- hiddenPreviewsBodyPlaceholder: "",
- options: .customDismissAction)
-
+
+ // set action and reply buttons
+ func setActions(btnText: String, isPushActionButton : Bool, is2Way: Bool){
+ var actions: [UNNotificationAction] = []
+ PushKConstants.logger.debug("start setActions, isPushActionButton: \(isPushActionButton), is2Way: \(is2Way)")
+ if(isPushActionButton && is2Way){
+ let acceptAction = UNNotificationAction(identifier: "pushKNotificationActionId",
+ title: btnText, options: [UNNotificationActionOptions.foreground])
+ let replyAction = UNTextInputNotificationAction(identifier: "pushKReplyActionId", title: "Reply", options: [])
+
+ actions.append(acceptAction)
+ actions.append(replyAction)
+ }else{
+ if(isPushActionButton && !is2Way){
+ let acceptAction = UNNotificationAction(identifier: "pushKNotificationActionId",
+ title: btnText, options: [UNNotificationActionOptions.foreground])
+
+ actions.append(acceptAction)
+ }else{
+ let replyAction = UNTextInputNotificationAction(identifier: "pushKReplyActionId", title: "Reply", options: [])
+
+ actions.append(replyAction)
+ }
+ }
+
+ let pushCategory = UNNotificationCategory(identifier: "pushKActionCategory",
+ actions: actions,
+ intentIdentifiers: [],
+ hiddenPreviewsBodyPlaceholder: "",
+ options: .customDismissAction)
+
UNUserNotificationCenter.current().setNotificationCategories([pushCategory])
}
diff --git a/PushSDK/models/DataStructures.swift b/PushSDK/models/DataStructures.swift
index 7ec20c3..2cbbbcc 100644
--- a/PushSDK/models/DataStructures.swift
+++ b/PushSDK/models/DataStructures.swift
@@ -122,9 +122,10 @@ public struct MessagesResponseStr {
public var button: ButtonResponse?=nil
public var time: String?=""
public var partner: String?=""
+ public var is2Way:Bool?=false
public func toString() -> String {
- return "MessagesResponseStr(phone: \(self.phone ?? ""), messageId: \(self.messageId ?? ""), title: \(self.title ?? ""), body: \(self.body ?? ""), image: \(self.image?.toString() ?? ""), button: \(self.button?.toString() ?? ""), time: \(self.time ?? ""), partner: \(self.partner ?? ""))"
+ return "MessagesResponseStr(phone: \(self.phone ?? ""), messageId: \(self.messageId ?? ""), title: \(self.title ?? ""), body: \(self.body ?? ""), image: \(self.image?.toString() ?? ""), button: \(self.button?.toString() ?? ""), time: \(self.time ?? ""), partner: \(self.partner ?? ""), is2Way: \(self.is2Way ?? false))"
}
}
diff --git a/PushSDK/settings/PushConstants.swift b/PushSDK/settings/PushConstants.swift
index 758334e..de00904 100644
--- a/PushSDK/settings/PushConstants.swift
+++ b/PushSDK/settings/PushConstants.swift
@@ -28,7 +28,7 @@ public struct PushKConstants {
let kOSType = "ios"
static let serverSdkVersion = "2.3"
- static let sdkVersion = "1.1.3"
+ static let sdkVersion = "1.1.4"
static let devOSName = UIDevice.current.systemName
static let devOSVersion = UIDevice.current.systemVersion
static let deviceType = "\(UIDevice.current.model)"
diff --git a/README.md b/README.md
index ad0d2f9..87230a0 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ To open your project run $ open ProjectName.xcworkspace
More about Cocoapods and Podfile here - https://cocoapods.org, https://guides.cocoapods.org/using/the-podfile.html and https://guides.cocoapods.org/using/using-cocoapods.html.
### Add sdk to your project.
-Last actual SDK version: 1.1.3
+Last actual SDK version: 1.1.4
To integrate PushSDK to your project with COCOAPODS (https://guides.cocoapods.org/using/the-podfile.html) add the next line in Podfile.
pod 'PushSDK', :git => 'https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS', :branch => 'main'
@@ -198,6 +198,30 @@ pushAdapterSdk.areNotificationsEnabled { (notificationStatus) in
```
***
+## Using reply button in notification
+### The reply button empowers end users to make a response to the push message directly from notification.
+### You can catch user's response and process it by using followed code (in an extension of ViewController/AppDelegate:UNUserNotificationCenterDelegate)
+```swift
+func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+
+ let userInfo = response.notification.request.content.userInfo
+
+ switch response.actionIdentifier{
+
+ ***
+
+ case "pushKReplyActionId":
+ if let reply = (response as? UNTextInputNotificationResponse)?.userText{
+ PushKConstants.logger.debug("user response: \(reply)")
+ }
+
+ default:
+ break
+ }
+
+ completionHandler()
+}
+```
# SDK functions description