Skip to content

Commit 248c18e

Browse files
committed
In-App Message was causing a crash
* Fixes #539, constraint conflict in specific scenario with In-App Message fixed by removing all constraints on setup * Changed some DEBUG onesignal logs to VERBOSE
1 parent 7f85d89 commit 248c18e

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ - (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber *newHeight))
104104
return;
105105
}
106106
NSString *successMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Success: %@", OS_JS_GET_PAGE_META_DATA_METHOD, result];
107-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:successMessage];
107+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:successMessage];
108108

109109
[self setupWebViewConstraints];
110110

@@ -119,6 +119,8 @@ - (NSNumber *)extractHeightFromMetaDataPayload:(NSDictionary *)result {
119119
}
120120

121121
- (void)setupWebViewConstraints {
122+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Setting up In-App Message WebView Constraints"];
123+
122124
[self.webView removeConstraints:[self.webView constraints]];
123125

124126
self.webView.translatesAutoresizingMaskIntoConstraints = false;

iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ - (void)viewWillDisappear:(BOOL)animated {
121121
}
122122

123123
- (void)applicationIsActive:(NSNotification *)notification {
124-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Application Active"];
124+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Application Active"];
125125

126126
// Animate the showing of the IAM when opening the app from background
127127
[self animateAppearance];
128128
}
129129

130130
- (void)applicationIsInBackground:(NSNotification *)notification {
131-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Application Entered Background"];
131+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Application Entered Background"];
132132

133133
// Get current orientation of the device
134134
UIDeviceOrientation currentDeviceOrientation = UIDevice.currentDevice.orientation;
@@ -152,7 +152,10 @@ - (void)addAppEnterBackgroundObserver {
152152
Wait until the actual HTML content is loaded before animating appearance
153153
*/
154154
- (void)setupInitialMessageUI {
155-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"In App Message Setup"];
155+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Setting up In-App Message"];
156+
157+
// Remove all of the constraints connected to the messageView
158+
[self.messageView removeConstraints:[self.messageView constraints]];
156159

157160
self.messageView.delegate = self;
158161

@@ -172,7 +175,7 @@ - (void)setupInitialMessageUI {
172175
}
173176

174177
- (void)displayMessage {
175-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Displaying In App Message"];
178+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Displaying In App Message"];
176179

177180
// Sets up the message view in a hidden position while we wait
178181
[self setupInitialMessageUI];
@@ -211,7 +214,7 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
211214
}
212215

213216
let message = [NSString stringWithFormat:@"In App Messaging htmlContent.html: %@", data[@"hmtl"]];
214-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:message];
217+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:message];
215218

216219
let baseUrl = [NSURL URLWithString:SERVER_URL];
217220
NSString* htmlContent = data[@"html"];
@@ -244,6 +247,8 @@ Sets up the message view in its initial (hidden) position
244247
Once the HTML content is loaded, we call animateAppearance() to show the message view
245248
*/
246249
- (void)addConstraintsForMessage {
250+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Setting up In-App Message Constraints"];
251+
247252
// Initialize the anchors that describe the edges of the view, such as the top, bottom, etc.
248253
NSLayoutAnchor *top = self.view.topAnchor,
249254
*bottom = self.view.bottomAnchor,
@@ -269,13 +274,13 @@ - (void)addConstraintsForMessage {
269274
CGFloat marginSpacing = [OneSignalViewHelper sizeToScale:MESSAGE_MARGIN];
270275

271276
let screenHeight = [NSString stringWithFormat:@"Screen Bounds Height: %f", mainBounds.size.height];
272-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:screenHeight];
277+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:screenHeight];
273278
let screenWidth = [NSString stringWithFormat:@"Screen Bounds Width: %f", mainBounds.size.width];
274-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:screenWidth];
275-
let heightMessage = [NSString stringWithFormat:@"In App Message Height: %f", self.message.height.doubleValue];
276-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:heightMessage];
279+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:screenWidth];
277280
let screenScale = [NSString stringWithFormat:@"Screen Bounds Scale: %f", UIScreen.mainScreen.scale];
278-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:screenScale];
281+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:screenScale];
282+
let heightMessage = [NSString stringWithFormat:@"In App Message Height: %f", self.message.height.doubleValue];
283+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:heightMessage];
279284

280285
// Height constraint based on the IAM being full screen or any others with a specific height
281286
// NOTE: full screen IAM payload has no height, so match screen height minus margins
@@ -589,9 +594,9 @@ - (void)jsEventOccurredWithBody:(NSData *)body {
589594
let event = [OSInAppMessageBridgeEvent instanceWithData:body];
590595

591596
NSString *eventMessage = [NSString stringWithFormat:@"Action Occured with Event: %@", event];
592-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:eventMessage];
597+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:eventMessage];
593598
NSString *eventTypeMessage = [NSString stringWithFormat:@"Action Occured with Event Type: %lu", (unsigned long)event.type];
594-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:eventTypeMessage];
599+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:eventTypeMessage];
595600

596601
if (event) {
597602
if (event.type == OSInAppMessageBridgeEventTypePageRenderingComplete) {
@@ -630,7 +635,7 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
630635
/*
631636
Code here will execute before the orientation change begins
632637
*/
633-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Screen Orientation Change Detected"];
638+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Screen Orientation Change Detected"];
634639

635640
UIApplicationState appState = UIApplication.sharedApplication.applicationState;
636641

@@ -641,7 +646,7 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
641646
if (currentOrientation == OrientationInvalid &&
642647
(appState == UIApplicationStateInactive || appState == UIApplicationStateBackground)) {
643648

644-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Orientation Change Ended: Orientation same as previous or invalid orientation"];
649+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Orientation Change Ended: Orientation same as previous or invalid orientation"];
645650

646651
self.previousOrientation = currentOrientation;
647652

@@ -650,7 +655,7 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
650655

651656
self.previousOrientation = currentOrientation;
652657

653-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Orientation Change Started: Hiding IAM"];
658+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Orientation Change Started: Hiding IAM"];
654659

655660
// Deactivate the pan constraint while changing the screen orientation
656661
self.panVerticalConstraint.active = false;
@@ -662,7 +667,7 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
662667
/*
663668
Code here will execute during the rotation
664669
*/
665-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Orientation Change Occurring: Removing all previous IAM constraints"];
670+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Orientation Change Occurring: Removing all previous IAM constraints"];
666671

667672
// Remove all of the constraints connected to the messageView
668673
[self.messageView removeConstraints:[self.messageView constraints]];
@@ -672,11 +677,11 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
672677
/*
673678
Code here will execute after the rotation has finished
674679
*/
675-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Orientation Change Complete: Getting new height from JS getPageMetaData()"];
680+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Orientation Change Complete: Getting new height from JS getPageMetaData()"];
676681

677682
// Evaluate the JS getPageMetaData() to obtain the new height for the webView and use it within the completion callback to set the new height
678683
[self.messageView resetWebViewToMaxBoundsAndResizeHeight:^(NSNumber *newHeight) {
679-
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:@"Orientation Change Complete with New Height: Adding constraints again and showing IAM"];
684+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Orientation Change Complete with New Height: Adding constraints again and showing IAM"];
680685

681686
// Assign new height to message
682687
self.message.height = newHeight;

0 commit comments

Comments
 (0)