Skip to content

Commit b535171

Browse files
authored
Add interface for CT push handlers (#563)
1 parent e627045 commit b535171

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

LeanplumSDK/LeanplumSDK/Classes/Internal/Leanplum.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,24 @@ + (void)setShouldOpenNotificationHandler:(LeanplumShouldHandleNotificationBlock)
16221622
LP_END_TRY
16231623
}
16241624

1625+
+ (void)setCleverTapOpenDeepLinksInForeground:(BOOL)openDeepLinksInForeground
1626+
{
1627+
LPCTNotificationsManager *manager = (LPCTNotificationsManager *)[Leanplum notificationsManager];
1628+
[manager setOpenDeepLinksInForeground:openDeepLinksInForeground];
1629+
}
1630+
1631+
+ (void)setHandleCleverTapNotification:(LeanplumHandleCleverTapNotificationBlock)block
1632+
{
1633+
if (!block) {
1634+
[self throwError:@"[Leanplum setHandleCleverTapNotification:] Nil block parameter "
1635+
@"provided."];
1636+
return;
1637+
}
1638+
LP_TRY
1639+
((LPCTNotificationsManager *)[Leanplum notificationsManager]).handleCleverTapNotificationBlock = block;
1640+
LP_END_TRY
1641+
}
1642+
16251643
+ (void)setPushDeliveryTrackingEnabled:(BOOL)enabled
16261644
{
16271645
LP_TRY

LeanplumSDK/LeanplumSDK/Classes/Leanplum.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ typedef void (^LeanplumSetLocationBlock)(BOOL success);
145145
typedef BOOL (^LeanplumActionBlock)(LPActionContext* context);
146146
typedef void (^LeanplumHandleNotificationBlock)(void);
147147
typedef void (^LeanplumShouldHandleNotificationBlock)(NSDictionary *userInfo, LeanplumHandleNotificationBlock response);
148+
typedef void (^LeanplumHandleCleverTapNotificationBlock)(NSDictionary *userInfo,
149+
BOOL isNotificationOpen,
150+
LeanplumHandleNotificationBlock response);
148151
typedef void (^LeanplumPushSetupBlock)(void);
149152
/**@}*/
150153

@@ -436,6 +439,22 @@ NS_SWIFT_NAME(defineAction(name:kind:args:options:present:dismiss:));
436439
*/
437440
+ (void)setShouldOpenNotificationHandler:(LeanplumShouldHandleNotificationBlock)block;
438441

442+
/**
443+
* CleverTap push notifications specific.
444+
* Sets whether a notification's deeplink should be opened when push notification is recevied while the app is on the foreground.
445+
* Default value is false.
446+
*/
447+
+ (void)setCleverTapOpenDeepLinksInForeground:(BOOL)openDeepLinksInForeground;
448+
449+
/**
450+
* CleverTap push notifications specific.
451+
* Block to call that decides how to handle a CleverTap push notification.
452+
* received while the app is running, and the notification is not muted.
453+
* The block provides the notification userInfo, a bool if the push is received or opened, and a block with the default implementation.
454+
* @see LeanplumHandleCleverTapNotificationBlock for details.
455+
*/
456+
+ (void)setHandleCleverTapNotification:(LeanplumHandleCleverTapNotificationBlock)block;
457+
439458
/**
440459
* Sets if a Deliver event should be tracked when a Push Notification is received.
441460
* Default value is true - event is tracked.

LeanplumSDK/LeanplumSDK/ClassesSwift/Migration/LPCTNotificationsManager.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import Foundation
1010
@_implementationOnly import CleverTapSDK
1111

1212
@objc public class LPCTNotificationsManager: NotificationsManager {
13-
struct Constants {
14-
static let OpenDeepLinksInForeground = true
15-
}
13+
@objc public var openDeepLinksInForeground = false
14+
@objc public var handleCleverTapNotificationBlock: LeanplumHandleCleverTapNotificationBlock?
15+
1616

1717
enum NotificationEvent: String, CustomStringConvertible {
1818
case opened = "Open"
@@ -57,13 +57,25 @@ import Foundation
5757
}
5858

5959
func handleCleverTapNotification(userInfo: [AnyHashable : Any], event: NotificationEvent) {
60-
handleWithCleverTapInstance {
61-
Log.info("""
60+
let handleNotification = {
61+
let openInForeground = self.openDeepLinksInForeground
62+
self.handleWithCleverTapInstance {
63+
Log.info("""
6264
[Wrapper] Calling CleverTap.handlePushNotification:openDeepLinksInForeground: \
63-
\(Constants.OpenDeepLinksInForeground) for Push \(event)
65+
\(openInForeground) for Push \(event)
6466
""")
65-
CleverTap.handlePushNotification(userInfo, openDeepLinksInForeground: Constants.OpenDeepLinksInForeground)
67+
CleverTap.handlePushNotification(userInfo, openDeepLinksInForeground: openInForeground)
68+
}
6669
}
70+
71+
// Execute custom block
72+
if let block = self.handleCleverTapNotificationBlock {
73+
Log.info("[Wrapper] Calling custom handleCleverTapNotificationBlock")
74+
block(userInfo, event == .opened, handleNotification)
75+
return
76+
}
77+
78+
handleNotification()
6779
}
6880

6981
func handleWithCleverTapInstance(action: @escaping () -> ()) {

0 commit comments

Comments
 (0)