Skip to content

Commit

Permalink
Update custom actions to replicate app changes
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpdiaz8 committed Dec 5, 2023
1 parent 5c1ab44 commit 54d77ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
70 changes: 35 additions & 35 deletions Sources/TwilioEngage/TwilioEngage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,12 @@ extension TwilioEngage: RemoteNotifications {
case "open_url":
handleOpenUrls(userInfo: userInfo)
default:
handleCustomAction(userInfo: userInfo)
handleCustomAction(userInfo: userInfo, identity: identity)
}
}

func handleOpenUrlsActionButtons(id: String) {
if let actionLink = userDefaults?.string(forKey: "ActionLink-\(id)") as? String {
guard let url = URL(string: actionLink) else {return}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
userDefaults?.removeObject(forKey: "ActionLink-\(id)")
}
}

func handleDeepLinksActionButtons(userInfo: [AnyHashable: Any], id: String) {
if let actionLink = userDefaults?.string(forKey: "ActionDeepLink-\(id)") as? String {
func handleDeepLinks(userInfo: [AnyHashable: Any]) {
if let actionLink = userInfo["link"] as? String {
var deepLinkData: [AnyHashable: Any] = [
"deep_link": actionLink,
]
Expand All @@ -234,26 +226,39 @@ extension TwilioEngage: RemoteNotifications {
deepLinkData.merge(userInfo) { (current, _) in current }

Notification.Name.openButton.post(userInfo: deepLinkData)
userDefaults?.removeObject(forKey: "ActionDeepLink-\(id)")
}
}

func handleCustomActionButtons(userInfo: [AnyHashable: Any], id: String) {
if let customAction = userDefaults?.string(forKey: "CustomAction-\(id)") as? String {
var deepLinkData: [AnyHashable: Any] = [
"custom_action": customAction,
func handleOpenUrls(userInfo: [AnyHashable: Any]) {
if let urlString = userInfo["link"] as? String {
guard let url = URL(string: urlString) else {return}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

func handleCustomAction(userInfo: [AnyHashable: Any], identity: String) {
if identity != "" {
var customActionData: [AnyHashable: Any] = [
"custom_action": identity,
]

//merge existing userInfo into deepLinkData dictionary
deepLinkData.merge(userInfo) { (current, _) in current }
//merge existing userInfo into customActionData dictionary
customActionData.merge(userInfo) { (current, _) in current }

Notification.Name.openButton.post(userInfo: deepLinkData)
userDefaults?.removeObject(forKey: "CustomAction-\(id)")
Notification.Name.openButton.post(userInfo: customActionData)
}
}

func handleDeepLinks(userInfo: [AnyHashable: Any]) {
if let actionLink = userInfo["link"] as? String {
func handleOpenUrlsActionButtons(id: String) {
if let actionLink = userDefaults?.string(forKey: "ActionLink-\(id)") as? String {
guard let url = URL(string: actionLink) else {return}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
userDefaults?.removeObject(forKey: "ActionLink-\(id)")
}
}

func handleDeepLinksActionButtons(userInfo: [AnyHashable: Any], id: String) {
if let actionLink = userDefaults?.string(forKey: "ActionDeepLink-\(id)") as? String {
var deepLinkData: [AnyHashable: Any] = [
"deep_link": actionLink,
]
Expand All @@ -262,26 +267,21 @@ extension TwilioEngage: RemoteNotifications {
deepLinkData.merge(userInfo) { (current, _) in current }

Notification.Name.openButton.post(userInfo: deepLinkData)
userDefaults?.removeObject(forKey: "ActionDeepLink-\(id)")
}
}

func handleOpenUrls(userInfo: [AnyHashable: Any]) {
if let urlString = userInfo["link"] as? String {
guard let url = URL(string: urlString) else {return}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

func handleCustomAction(userInfo: [AnyHashable: Any]) {
if let customAction = userInfo["link"] as? String {
var deepLinkData: [AnyHashable: Any] = [
func handleCustomActionButtons(userInfo: [AnyHashable: Any], id: String) {
if let customAction = userDefaults?.string(forKey: "CustomAction-\(id)") as? String {
var customActionData: [AnyHashable: Any] = [
"custom_action": customAction,
]

//merge existing userInfo into deepLinkData dictionary
deepLinkData.merge(userInfo) { (current, _) in current }
//merge existing userInfo into customActionData dictionary
customActionData.merge(userInfo) { (current, _) in current }

Notification.Name.openButton.post(userInfo: deepLinkData)
Notification.Name.openButton.post(userInfo: customActionData)
userDefaults?.removeObject(forKey: "CustomAction-\(id)")
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions Sources/TwilioEngage/TwilioEngageServiceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,18 @@ public class TwilioEngageServiceExtension: UtilityPlugin {
let categories: Set = [category]
UNUserNotificationCenter.current().setNotificationCategories(categories)

if actionIdentifier == "open_url" {
if (actionIdentifier == "open_app") {
continue
} else if actionIdentifier == "open_url" {
if let link = actionButton["link"] as? String {
userDefaults?.set(link, forKey: "ActionLink-\(id)");
userDefaults?.set(link, forKey: "ActionLink-\(id)")
}
}

if actionIdentifier == "deep_link" {
if let link = actionButton["link"] as? String {
userDefaults?.set(link, forKey: "ActionDeepLink-\(id)");
}
}

if actionIdentifier == "custom_action" {
} else if actionIdentifier == "deep_link" {
if let link = actionButton["link"] as? String {
userDefaults?.set(link, forKey: "CustomAction-\(id)");
userDefaults?.set(link, forKey: "ActionDeepLink-\(id)")
}
} else {
userDefaults?.set(actionIdentifier, forKey: "CustomAction-\(id)")
}
}
}
Expand Down

0 comments on commit 54d77ad

Please sign in to comment.