Skip to content

Commit

Permalink
Merge pull request #8 from GlobalMessageServices/RDGMS-844-implement-…
Browse files Browse the repository at this point in the history
…reply-button-in-i-os-sdk

Rdgms 844 implement reply button in i os sdk
  • Loading branch information
Oleksii Korniienko authored Jan 26, 2023
2 parents ad26f31 + c345dcf commit 68e0708
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion PushSDK.podspec
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions PushSDK/PushSDKFirebase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
Expand Down Expand Up @@ -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 ?? [:])
}

Expand Down
3 changes: 2 additions & 1 deletion PushSDK/core/JsonParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
54 changes: 40 additions & 14 deletions PushSDK/core/Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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)

}

Expand Down Expand Up @@ -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])
}

Expand Down
3 changes: 2 additions & 1 deletion PushSDK/models/DataStructures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
}
}

Expand Down
2 changes: 1 addition & 1 deletion PushSDK/settings/PushConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To open your project run $ open ProjectName.xcworkspace<br>
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<br>
Last actual SDK version: 1.1.4<br>
To integrate PushSDK to your project with COCOAPODS (https://guides.cocoapods.org/using/the-podfile.html) add the next line in Podfile.<br>
pod 'PushSDK', :git => 'https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS', :branch => 'main'

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 68e0708

Please sign in to comment.