Skip to content

Update custom actions to replicate app changes #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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