Skip to content

Commit 494bf10

Browse files
authored
Merge pull request #1261 from OneSignal/5.0.0/iam_click_listener_api
[5.0.0] IAM Click Listener - API update
2 parents c5dad91 + 553d31c commit 494bf10

30 files changed

+332
-227
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import <UIKit/UIKit.h>
3232
#import <OneSignalFramework/OneSignalFramework.h>
3333

34-
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener>
34+
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener>
3535

3636
@property (strong, nonatomic) UIWindow *window;
3737

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ - (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-
70-
// Example block for IAM action click handler
71-
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
72-
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
73-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
74-
};
75-
76-
// Example setter for IAM action click handler using OneSignal public method
77-
[OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock];
78-
7960
// OneSignal Init with app id and lauch options
8061
[OneSignal setLaunchURLsInApp:YES];
8162
[OneSignal setProvidesNotificationSettingsView:NO];
@@ -84,13 +65,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8465
[OneSignal.InAppMessages paused:true];
8566

8667
[OneSignal.Notifications addForegroundLifecycleListener:self];
87-
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];
88-
68+
[OneSignal.Notifications addClickListener:self];
8969
[OneSignal.User.pushSubscription addObserver:self];
9070
NSLog(@"OneSignal Demo App push subscription observer added");
9171

9272
[OneSignal.Notifications addPermissionObserver:self];
93-
73+
[OneSignal.InAppMessages addClickListener:self];
74+
9475
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
9576

9677
return YES;
@@ -123,11 +104,14 @@ - (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState *)s
123104
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) state.current.optedIn;
124105
}
125106

107+
- (void)onClickNotification:(OSNotificationClickEvent * _Nonnull)event {
108+
NSLog(@"Dev App onClickNotification with event %@", [event jsonRepresentation]);
109+
}
110+
126111
#pragma mark OSInAppMessageDelegate
127112

128-
- (void)handleMessageAction:(OSInAppMessageAction *)action {
129-
NSLog(@"OSInAppMessageDelegate: handling message action: %@",action);
130-
return;
113+
- (void)onClickInAppMessage:(OSInAppMessageClickEvent * _Nonnull)event {
114+
NSLog(@"Dev App onClickInAppMessage event: %@", [event jsonRepresentation]);
131115
}
132116

133117
- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
@@ -139,22 +123,22 @@ - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
139123
}
140124

141125
- (void)onWillDisplayInAppMessage:(OSInAppMessageWillDisplayEvent *)event {
142-
NSLog(@"OSInAppMessageDelegate: onWillDisplay Message: %@",event.message);
126+
NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDisplay Message: %@",event.message);
143127
return;
144128
}
145129

146130
- (void)onDidDisplayInAppMessage:(OSInAppMessageDidDisplayEvent *)event {
147-
NSLog(@"OSInAppMessageDelegate: onDidDisplay Message: %@",event.message);
131+
NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDisplay Message: %@",event.message);
148132
return;
149133
}
150134

151135
- (void)onWillDismissInAppMessage:(OSInAppMessageWillDismissEvent *)event {
152-
NSLog(@"OSInAppMessageDelegate: onWillDismiss Message: %@",event.message);
136+
NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDismiss Message: %@",event.message);
153137
return;
154138
}
155139

156140
- (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent *)event {
157-
NSLog(@"OSInAppMessageDelegate: onDidDismiss Message: %@",event.message);
141+
NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDismiss Message: %@",event.message);
158142
return;
159143
}
160144

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import <UIKit/UIKit.h>
3232
#import <OneSignalFramework/OneSignalFramework.h>
3333

34-
@interface ViewController : UIViewController <OSInAppMessageDelegate>
34+
@interface ViewController : UIViewController
3535

3636
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
3737
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
190190
[OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex];
191191
}
192192

193-
- (void)handleMessageAction:(NSString *)actionId {
194-
NSLog(@"View controller did get action: %@", actionId);
195-
}
196-
197193
- (IBAction)loginExternalUserId:(UIButton *)sender {
198194
NSString* externalUserId = self.externalUserIdTextField.text;
199195
NSLog(@"Dev App: Logging in to external user ID %@", externalUserId);

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5454
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
5555
[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE];
5656
_notificationDelegate = [OneSignalNotificationCenterDelegate new];
57-
58-
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
59-
NSLog(@"OSNotificationOpenedResult: %@", result.action);
60-
};
61-
62-
// Example block for IAM action click handler
63-
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
64-
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
65-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
66-
};
67-
68-
// Example setter for IAM action click handler using OneSignal public method
69-
[OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock];
70-
57+
7158
// OneSignal Init with app id and lauch options
7259
[OneSignal setLaunchURLsInApp:YES];
7360
[OneSignal setProvidesNotificationSettingsView:NO];
@@ -83,8 +70,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8370

8471
[OneSignal.InAppMessages paused:false];
8572

86-
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];
87-
8873
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
8974

9075
return YES;

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import <UIKit/UIKit.h>
3232
#import <OneSignalFramework/OneSignalFramework.h>
3333

34-
@interface ViewController : UIViewController <OSInAppMessageDelegate>
34+
@interface ViewController : UIViewController
3535

3636
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
3737
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
144144
[OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex];
145145
}
146146

147-
- (void)handleMessageAction:(NSString *)actionId {
148-
NSLog(@"View controller did get action: %@", actionId);
149-
}
150-
151147
- (IBAction)loginExternalUserId:(UIButton *)sender {
152148
NSLog(@"setExternalUserId is no longer supported. Please use login or addAlias.");
153149
// TODO: Update

0 commit comments

Comments
 (0)