@@ -57,44 +57,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5757
5858 _notificationDelegate = [OneSignalNotificationCenterDelegate new ];
5959
60- id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
61- // TODO: opened handler Not triggered
62- NSLog (@" OSNotificationOpenedResult: %@ " , result.action );
63- #pragma clang diagnostic push
64- #pragma clang diagnostic ignored "-Wdeprecated"
65- UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: @" Notifiation Opened In App Delegate" message: @" Notification Opened In App Delegate" delegate: self cancelButtonTitle: @" Delete" otherButtonTitles: @" Cancel" , nil ];
66- [alert show ];
67- #pragma clang diagnostic pop
68- };
69- id notificationReceiverBlock = ^(OSNotification *notif, OSNotificationDisplayResponse completion) {
70- NSLog (@" Will Receive Notification - %@ " , notif.notificationId );
71- completion (notif);
72- };
73-
74- // Example block for IAM action click handler
75- id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
76- NSString *message = [NSString stringWithFormat: @" Click Action Occurred: %@ " , [action jsonRepresentation ]];
77- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: message];
78- };
79-
80- // Example setter for IAM action click handler using OneSignal public method
81- [OneSignal.InAppMessages setClickHandler: inAppMessagingActionClickBlock];
82-
8360 // OneSignal Init with app id and lauch options
8461 [OneSignal setLaunchURLsInApp: YES ];
8562 [OneSignal setProvidesNotificationSettingsView: NO ];
8663
87- [OneSignal.InAppMessages setLifecycleHandler :self ];
64+ [OneSignal.InAppMessages addLifecycleListener :self ];
8865 [OneSignal.InAppMessages paused: true ];
8966
90- [OneSignal.Notifications setNotificationWillShowInForegroundHandler: notificationReceiverBlock];
91- [OneSignal.Notifications setNotificationOpenedHandler: openNotificationHandler];
92-
67+ [OneSignal.Notifications addForegroundLifecycleListener: self ];
68+ [OneSignal.Notifications addClickListener: self ];
9369 [OneSignal.User.pushSubscription addObserver: self ];
9470 NSLog (@" OneSignal Demo App push subscription observer added" );
9571
9672 [OneSignal.Notifications addPermissionObserver: self ];
97-
73+ [OneSignal.InAppMessages addClickListener: self ];
74+
9875 NSLog (@" UNUserNotificationCenter.delegate: %@ " , UNUserNotificationCenter .currentNotificationCenter .delegate );
9976
10077 return YES ;
@@ -117,40 +94,51 @@ + (void) setOneSignalAppId:(NSString*)onesignalAppId {
11794 // [OneSignal setAppId:onesignalAppId];
11895}
11996
120- - (void )onOSPermissionChanged : (OSPermissionState*) state {
121- NSLog (@" Dev App onOSPermissionChanged : %@ " , state );
97+ - (void )onNotificationPermissionDidChange : ( BOOL ) permission {
98+ NSLog (@" Dev App onNotificationPermissionDidChange : %d " , permission );
12299}
123100
124- - (void )onOSPushSubscriptionChangedWithStateChanges : (OSPushSubscriptionStateChanges *)stateChanges {
125- NSLog (@" Dev App onOSPushSubscriptionChangedWithStateChanges : %@ " , stateChanges );
101+ - (void )onPushSubscriptionDidChangeWithState : (OSPushSubscriptionChangedState *)state {
102+ NSLog (@" Dev App onPushSubscriptionDidChange : %@ " , state );
126103 ViewController* mainController = (ViewController*) self.window .rootViewController ;
127- mainController.subscriptionSegmentedControl .selectedSegmentIndex = (NSInteger ) stateChanges.to .optedIn ;
104+ mainController.subscriptionSegmentedControl .selectedSegmentIndex = (NSInteger ) state.current .optedIn ;
105+ }
106+
107+ - (void )onClickNotification : (OSNotificationClickEvent * _Nonnull)event {
108+ NSLog (@" Dev App onClickNotification with event %@ " , [event jsonRepresentation ]);
128109}
129110
130111#pragma mark OSInAppMessageDelegate
131112
132- - (void )handleMessageAction : (OSInAppMessageAction *)action {
133- NSLog (@" OSInAppMessageDelegate: handling message action: %@ " ,action);
134- return ;
113+ - (void )onClickInAppMessage : (OSInAppMessageClickEvent * _Nonnull)event {
114+ NSLog (@" Dev App onClickInAppMessage event: %@ " , [event jsonRepresentation ]);
115+ }
116+
117+ - (void )onWillDisplayNotification : (OSNotificationWillDisplayEvent *)event {
118+ NSLog (@" Dev App OSNotificationWillDisplayEvent with event: %@ " ,event);
119+ [event preventDefault ];
120+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue (), ^{
121+ [event.notification display ];
122+ });
135123}
136124
137- - (void )onWillDisplayInAppMessage : (OSInAppMessage *)message {
138- NSLog (@" OSInAppMessageDelegate : onWillDisplay Message: %@ " ,message);
125+ - (void )onWillDisplayInAppMessage : (OSInAppMessageWillDisplayEvent *)event {
126+ NSLog (@" Dev App OSInAppMessageLifecycleListener : onWillDisplay Message: %@ " ,event. message );
139127 return ;
140128}
141129
142- - (void )onDidDisplayInAppMessage : (OSInAppMessage *)message {
143- NSLog (@" OSInAppMessageDelegate : onDidDisplay Message: %@ " ,message);
130+ - (void )onDidDisplayInAppMessage : (OSInAppMessageDidDisplayEvent *)event {
131+ NSLog (@" Dev App OSInAppMessageLifecycleListener : onDidDisplay Message: %@ " ,event. message );
144132 return ;
145133}
146134
147- - (void )onWillDismissInAppMessage : (OSInAppMessage *)message {
148- NSLog (@" OSInAppMessageDelegate : onWillDismiss Message: %@ " ,message);
135+ - (void )onWillDismissInAppMessage : (OSInAppMessageWillDismissEvent *)event {
136+ NSLog (@" Dev App OSInAppMessageLifecycleListener : onWillDismiss Message: %@ " ,event. message );
149137 return ;
150138}
151139
152- - (void )onDidDismissInAppMessage : (OSInAppMessage *)message {
153- NSLog (@" OSInAppMessageDelegate : onDidDismiss Message: %@ " ,message);
140+ - (void )onDidDismissInAppMessage : (OSInAppMessageDidDismissEvent *)event {
141+ NSLog (@" Dev App OSInAppMessageLifecycleListener : onDidDismiss Message: %@ " ,event. message );
154142 return ;
155143}
156144
0 commit comments