From f7818b279ef0a0b8c285dd615d532cc170807b00 Mon Sep 17 00:00:00 2001 From: "Mike O. Abidakun" Date: Mon, 21 Aug 2023 09:03:41 +0100 Subject: [PATCH 1/3] Simplifies "notifyPushNotificationOpened" method by guaranteeing preconditions (using guard let), before continuing. --- ios/Classes/SwiftIterableFlutterPlugin.swift | 34 +++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/ios/Classes/SwiftIterableFlutterPlugin.swift b/ios/Classes/SwiftIterableFlutterPlugin.swift index d8cbe94..e5000a9 100644 --- a/ios/Classes/SwiftIterableFlutterPlugin.swift +++ b/ios/Classes/SwiftIterableFlutterPlugin.swift @@ -130,25 +130,21 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica } public func notifyPushNotificationOpened(){ - let userInfo = IterableAPI.lastPushPayload - - if(userInfo != nil){ - let apsInfo = userInfo!["aps"] as? [String: AnyObject] - let alertInfo = apsInfo?["alert"] as? [String: AnyObject] - - if(alertInfo != nil){ - - let payload = [ - "title": alertInfo?["title"] ?? "", - "body": alertInfo?["body"] ?? "", - "additionalData": IterableAPI.lastPushPayload! - ] as [String : Any] - - SwiftIterableFlutterPlugin.channel?.invokeMethod("openedNotificationHandler", arguments: payload) - } - + guard let userInfo = IterableAPI.lastPushPayload, + let apsInfo = userInfo["aps"] as? [String: AnyObject], + let alertInfo = apsInfo["alert"] as? [String: AnyObject] + else { + return } - } + let payload = [ + "title": alertInfo["title"] ?? "", + "body": alertInfo["body"] ?? "", + "additionalData": IterableAPI.lastPushPayload! + ] as [String : Any] + + SwiftIterableFlutterPlugin.channel?.invokeMethod("openedNotificationHandler", arguments: payload) + + } + } - From 098ff1ea9d399a4d5594ab2b71bfd4c934a74889 Mon Sep 17 00:00:00 2001 From: "Mike O. Abidakun" Date: Mon, 21 Aug 2023 09:12:53 +0100 Subject: [PATCH 2/3] Makes SwiftIterableFlutterPlugin class conform to IterableURLDelegate protocol so that it can receive and propagate Iterable push notifications that are configured with the "Open URL" action. With this change in place, the openedNotificationHandler in the Flutter application will now also be called for Iterable push notifications that are set-up in Iterable as having the Open action behaviour type set to "Open URL". Prior to this change, the Flutter application would not be called when configured as "Open URL" so deep-link use cases were not supported. --- ios/Classes/SwiftIterableFlutterPlugin.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftIterableFlutterPlugin.swift b/ios/Classes/SwiftIterableFlutterPlugin.swift index e5000a9..5024949 100644 --- a/ios/Classes/SwiftIterableFlutterPlugin.swift +++ b/ios/Classes/SwiftIterableFlutterPlugin.swift @@ -3,7 +3,7 @@ import UIKit import IterableSDK import UserNotifications -public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotificationCenterDelegate, IterableCustomActionDelegate { +public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotificationCenterDelegate, IterableCustomActionDelegate, IterableURLDelegate { static var channel: FlutterMethodChannel? = nil @@ -78,6 +78,7 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica config.pushIntegrationName = pushIntegrationName config.autoPushRegistration = true config.customActionDelegate = self + config.urlDelegate = self IterableAPI.initialize(apiKey: apiKey, config: config) } @@ -129,6 +130,12 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica return true; } + + public func handle(iterableURL url: URL, inContext context: IterableActionContext) -> Bool { + notifyPushNotificationOpened() + return true + } + public func notifyPushNotificationOpened(){ guard let userInfo = IterableAPI.lastPushPayload, let apsInfo = userInfo["aps"] as? [String: AnyObject], From 3bbe5a62b27822dd938cc6d3c5b60d6bdbcad4c5 Mon Sep 17 00:00:00 2001 From: "Mike O. Abidakun" Date: Mon, 21 Aug 2023 09:51:28 +0100 Subject: [PATCH 3/3] Update SwiftIterableFlutterPlugin.swift Re-uses the userInfo reference to IterableAPI.lastPushPayload, since we have it. --- ios/Classes/SwiftIterableFlutterPlugin.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/SwiftIterableFlutterPlugin.swift b/ios/Classes/SwiftIterableFlutterPlugin.swift index 5024949..c08907e 100644 --- a/ios/Classes/SwiftIterableFlutterPlugin.swift +++ b/ios/Classes/SwiftIterableFlutterPlugin.swift @@ -147,7 +147,7 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica let payload = [ "title": alertInfo["title"] ?? "", "body": alertInfo["body"] ?? "", - "additionalData": IterableAPI.lastPushPayload! + "additionalData": userInfo ] as [String : Any] SwiftIterableFlutterPlugin.channel?.invokeMethod("openedNotificationHandler", arguments: payload)