Skip to content
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

Chore: Add support for Iterable Push notifications with Open URL open action behaviour on iOS. #66

Merged
Merged
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
43 changes: 23 additions & 20 deletions ios/Classes/SwiftIterableFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -129,26 +130,28 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica
return true;
}


public func handle(iterableURL url: URL, inContext context: IterableActionContext) -> Bool {
notifyPushNotificationOpened()
return true
}

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": userInfo
] as [String : Any]

SwiftIterableFlutterPlugin.channel?.invokeMethod("openedNotificationHandler", arguments: payload)

}

}

Loading