Skip to content

Commit

Permalink
Merge pull request #1255 from OneSignal/5.0.0/api_updates_part_1
Browse files Browse the repository at this point in the history
[5.0.0] API Updates
  • Loading branch information
emawby authored May 1, 2023
2 parents 37ad22a + 0621f61 commit ac3c98e
Show file tree
Hide file tree
Showing 51 changed files with 893 additions and 565 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, OSPermissionObserver, OSInAppMessageLifecycleHandler, OSPushSubscriptionObserver>
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener>

@property (strong, nonatomic) UIWindow *window;

Expand Down
76 changes: 32 additions & 44 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,21 @@ - (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
};
id notificationReceiverBlock = ^(OSNotification *notif, OSNotificationDisplayResponse completion) {
NSLog(@"Will Receive Notification - %@", notif.notificationId);
completion(notif);
};

// 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];

[OneSignal.InAppMessages setLifecycleHandler:self];
[OneSignal.InAppMessages addLifecycleListener:self];
[OneSignal.InAppMessages paused:true];

[OneSignal.Notifications setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];

[OneSignal.Notifications addForegroundLifecycleListener:self];
[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,40 +94,51 @@ + (void) setOneSignalAppId:(NSString*)onesignalAppId {
// [OneSignal setAppId:onesignalAppId];
}

- (void)onOSPermissionChanged:(OSPermissionState*)state {
NSLog(@"Dev App onOSPermissionChanged: %@", state);
- (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 {
NSLog(@"Dev App OSNotificationWillDisplayEvent with event: %@",event);
[event preventDefault];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[event.notification display];
});
}

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

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

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

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

Expand Down
Loading

0 comments on commit ac3c98e

Please sign in to comment.