Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ @interface OSInAppMessageViewController ()
// We start the timer once the message is displayed (not during loading the content)
@property (weak, nonatomic, nullable) NSTimer *dismissalTimer;

// BOOL to track when an IAM has started UI setup so we know when to bypass UI changes on dismissal or not
// This is a fail safe for cases where global contraints are nil and we try to modify them on dismissal of an IAM
@property (nonatomic) BOOL didPageRenderingComplete;

@end

@implementation OSInAppMessageViewController
Expand Down Expand Up @@ -154,9 +158,6 @@ - (void)addAppEnterBackgroundObserver {
- (void)setupInitialMessageUI {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Setting up In-App Message"];

// Remove all of the constraints connected to the messageView
[self.messageView removeConstraints:[self.messageView constraints]];

self.messageView.delegate = self;

[self.messageView setupWebViewConstraints];
Expand All @@ -175,7 +176,7 @@ - (void)setupInitialMessageUI {
}

- (void)displayMessage {
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Displaying In App Message"];
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Displaying In-App Message"];

// Sets up the message view in a hidden position while we wait
[self setupInitialMessageUI];
Expand Down Expand Up @@ -231,9 +232,11 @@ - (void)loadMessageContent {
}

- (void)loadPreviewMessageContent {
[self.message loadPreviewMessageHTMLContentWithUUID:self.message.messageId success:[self messageContentOnSuccess] failure:^(NSError *error) {
[self encounteredErrorLoadingMessageContent:error];
}];
[self.message loadPreviewMessageHTMLContentWithUUID:self.message.messageId
success:[self messageContentOnSuccess]
failure:^(NSError *error) {
[self encounteredErrorLoadingMessageContent:error];
}];
}

- (void)encounteredErrorLoadingMessageContent:(NSError * _Nullable)error {
Expand Down Expand Up @@ -392,6 +395,13 @@ Dismisses the message view with a given direction (up or down) and velocity
*/
- (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {

// If the rendering event never occurs any constraints being adjusted for dismissal will be nil
// and we should bypass dismissal adjustments and animations and skip straight to the OSMessagingController callback for dismissing
if (!self.didPageRenderingComplete) {
[self.delegate messageViewControllerWasDismissed];
return;
}

// Inactivate the current Y constraints
self.finalYConstraint.active = false;
self.initialYConstraint.active = false;
Expand All @@ -407,7 +417,7 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
distance = self.view.frame.size.height - self.messageView.frame.origin.y + 8.0f;
[self.messageView.topAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:8.0f].active = true;
}

var dismissAnimationDuration = velocity != 0.0f ? distance / fabs(velocity) : 0.3f;

var animationOption = UIViewAnimationOptionCurveLinear;
Expand All @@ -430,7 +440,8 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
return;

[self dismissViewControllerAnimated:false completion:nil];


self.didPageRenderingComplete = false;
[self.delegate messageViewControllerWasDismissed];
}];
}
Expand Down Expand Up @@ -600,6 +611,10 @@ - (void)jsEventOccurredWithBody:(NSData *)body {

if (event) {
if (event.type == OSInAppMessageBridgeEventTypePageRenderingComplete) {

// BOOL set to true since the JS event fired, meaning the WebView was populated properly with the IAM code
self.didPageRenderingComplete = true;

self.message.position = event.renderingComplete.displayLocation;
self.message.height = event.renderingComplete.height;

Expand Down
9 changes: 4 additions & 5 deletions iOS_SDK/OneSignalSDK/Source/OSMessagingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ - (void)presentInAppPreviewMessage:(OSInAppMessage *)message {

- (void)displayMessage:(OSInAppMessage *)message {
self.isInAppMessageShowing = true;

self.viewController = [[OSInAppMessageViewController alloc] initWithMessage:message];
self.viewController.delegate = self;

dispatch_async(dispatch_get_main_queue(), ^{
[[self.viewController view] setNeedsLayout];
[self messageViewImpressionRequest:message];
});

[self messageViewImpressionRequest:message];
}

/*
Expand Down Expand Up @@ -294,12 +294,11 @@ - (void)messageViewControllerWasDismissed {
[self displayMessage:self.messageDisplayQueue.firstObject];
return;
} else {
// Hide and null our reference to the window to ensure there are no leaks
// Hide the window and call makeKeyWindow to ensure the IAM will not be shown
self.window.hidden = true;
[UIApplication.sharedApplication.delegate.window makeKeyWindow];
self.window = nil;

// Evaulate any IAMs (could be new or have now satisfied trigger conditions)
// Evaulate any IAMs (could be new IAM or added trigger conditions)
[self evaluateMessages];
}
}
Expand Down
3 changes: 1 addition & 2 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -1873,9 +1873,8 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict
return;

OSNotificationPayload *payload = [OSNotificationPayload parseWithApns:messageDict];
if ([OneSignalHelper handleIAMPreview:payload]) {
if ([OneSignalHelper handleIAMPreview:payload])
return;
}

onesignal_Log(ONE_S_LL_VERBOSE, @"handleNotificationOpened:isActive called!");

Expand Down
4 changes: 4 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,14 @@ + (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(
+ (BOOL)handleIAMPreview:(OSNotificationPayload *)payload {
NSString *uuid = [payload additionalData][ONESIGNAL_IAM_PREVIEW];
if (uuid) {

[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"IAM Preview Detected, Begin Handling"];
OSInAppMessage *message = [OSInAppMessage instancePreviewFromPayload:payload];
[[OSMessagingController sharedInstance] presentInAppPreviewMessage:message];
return YES;
}

[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"IAM Preview Not Detected, Handle Normal Notification"];
return NO;
}

Expand Down