Skip to content

Commit

Permalink
Merge pull request #1260 from OneSignal/5.0.0/push_subscription_obser…
Browse files Browse the repository at this point in the history
…ver_api

[5.0.0] Push Subscription Observer - API update
  • Loading branch information
emawby committed May 1, 2023
2 parents 9d27761 + 494bf10 commit d3613e2
Show file tree
Hide file tree
Showing 33 changed files with 358 additions and 253 deletions.
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import <UIKit/UIKit.h>
#import <OneSignalFramework/OneSignalFramework.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener>
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener>

@property (strong, nonatomic) UIWindow *window;

Expand Down
48 changes: 16 additions & 32 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

_notificationDelegate = [OneSignalNotificationCenterDelegate new];

id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
// TODO: opened handler Not triggered
NSLog(@"OSNotificationOpenedResult: %@", result.action);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notifiation Opened In App Delegate" message:@"Notification Opened In App Delegate" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
[alert show];
#pragma clang diagnostic pop
};

// Example block for IAM action click handler
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
};

// Example setter for IAM action click handler using OneSignal public method
[OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock];

// OneSignal Init with app id and lauch options
[OneSignal setLaunchURLsInApp:YES];
[OneSignal setProvidesNotificationSettingsView:NO];
Expand All @@ -84,13 +65,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[OneSignal.InAppMessages paused:true];

[OneSignal.Notifications addForegroundLifecycleListener:self];
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];

[OneSignal.Notifications addClickListener:self];
[OneSignal.User.pushSubscription addObserver:self];
NSLog(@"OneSignal Demo App push subscription observer added");

[OneSignal.Notifications addPermissionObserver:self];

[OneSignal.InAppMessages addClickListener:self];

NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);

return YES;
Expand All @@ -117,17 +98,20 @@ - (void)onNotificationPermissionDidChange:(BOOL)permission {
NSLog(@"Dev App onNotificationPermissionDidChange: %d", permission);
}

- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges {
NSLog(@"Dev App onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges);
- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState *)state {
NSLog(@"Dev App onPushSubscriptionDidChange: %@", state);
ViewController* mainController = (ViewController*) self.window.rootViewController;
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn;
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) state.current.optedIn;
}

- (void)onClickNotification:(OSNotificationClickEvent * _Nonnull)event {
NSLog(@"Dev App onClickNotification with event %@", [event jsonRepresentation]);
}

#pragma mark OSInAppMessageDelegate

- (void)handleMessageAction:(OSInAppMessageAction *)action {
NSLog(@"OSInAppMessageDelegate: handling message action: %@",action);
return;
- (void)onClickInAppMessage:(OSInAppMessageClickEvent * _Nonnull)event {
NSLog(@"Dev App onClickInAppMessage event: %@", [event jsonRepresentation]);
}

- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
Expand All @@ -139,22 +123,22 @@ - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
}

- (void)onWillDisplayInAppMessage:(OSInAppMessageWillDisplayEvent *)event {
NSLog(@"OSInAppMessageDelegate: onWillDisplay Message: %@",event.message);
NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDisplay Message: %@",event.message);
return;
}

- (void)onDidDisplayInAppMessage:(OSInAppMessageDidDisplayEvent *)event {
NSLog(@"OSInAppMessageDelegate: onDidDisplay Message: %@",event.message);
NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDisplay Message: %@",event.message);
return;
}

- (void)onWillDismissInAppMessage:(OSInAppMessageWillDismissEvent *)event {
NSLog(@"OSInAppMessageDelegate: onWillDismiss Message: %@",event.message);
NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDismiss Message: %@",event.message);
return;
}

- (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent *)event {
NSLog(@"OSInAppMessageDelegate: onDidDismiss Message: %@",event.message);
NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDismiss Message: %@",event.message);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import <UIKit/UIKit.h>
#import <OneSignalFramework/OneSignalFramework.h>

@interface ViewController : UIViewController <OSInAppMessageDelegate>
@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;
Expand Down
4 changes: 0 additions & 4 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
[OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex];
}

- (void)handleMessageAction:(NSString *)actionId {
NSLog(@"View controller did get action: %@", actionId);
}

- (IBAction)loginExternalUserId:(UIButton *)sender {
NSString* externalUserId = self.externalUserIdTextField.text;
NSLog(@"Dev App: Logging in to external user ID %@", externalUserId);
Expand Down
17 changes: 1 addition & 16 deletions iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE];
_notificationDelegate = [OneSignalNotificationCenterDelegate new];

id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
NSLog(@"OSNotificationOpenedResult: %@", result.action);
};

// Example block for IAM action click handler
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
};

// Example setter for IAM action click handler using OneSignal public method
[OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock];


// OneSignal Init with app id and lauch options
[OneSignal setLaunchURLsInApp:YES];
[OneSignal setProvidesNotificationSettingsView:NO];
Expand All @@ -83,8 +70,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

[OneSignal.InAppMessages paused:false];

[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];

NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);

return YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import <UIKit/UIKit.h>
#import <OneSignalFramework/OneSignalFramework.h>

@interface ViewController : UIViewController <OSInAppMessageDelegate>
@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;
Expand Down
4 changes: 0 additions & 4 deletions iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
[OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex];
}

- (void)handleMessageAction:(NSString *)actionId {
NSLog(@"View controller did get action: %@", actionId);
}

- (IBAction)loginExternalUserId:(UIButton *)sender {
NSLog(@"setExternalUserId is no longer supported. Please use login or addAlias.");
// TODO: Update
Expand Down
Loading

0 comments on commit d3613e2

Please sign in to comment.