Skip to content

Commit 58791ef

Browse files
authored
Merge pull request #1257 from OneSignal/5.0.0/iam_lifecycle_listener_api
[5.0.0] IAM Lifecycle Listener - API update
2 parents 4e1d615 + 412e65a commit 58791ef

38 files changed

+618
-364
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, OSInAppMessageLifecycleHandler, OSPushSubscriptionObserver>
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: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -121,36 +98,47 @@ - (void)onNotificationPermissionDidChange:(BOOL)permission {
12198
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

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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +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-
id notificationReceiverBlock = ^(OSNotification *notif, OSNotificationDisplayResponse completion) {
62-
NSLog(@"Will Receive Notification - %@", notif.notificationId);
63-
completion(notif);
64-
};
65-
66-
// Example block for IAM action click handler
67-
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
68-
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
69-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
70-
};
71-
72-
// Example setter for IAM action click handler using OneSignal public method
73-
[OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock];
74-
57+
7558
// OneSignal Init with app id and lauch options
7659
[OneSignal setLaunchURLsInApp:YES];
7760
[OneSignal setProvidesNotificationSettingsView:NO];
@@ -87,9 +70,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8770

8871
[OneSignal.InAppMessages paused:false];
8972

90-
[OneSignal.Notifications setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
91-
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];
92-
9373
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
9474

9575
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)