@@ -97,6 +97,8 @@ @interface OSInAppMessageViewController ()
9797
9898@property (nonatomic ) BOOL useWidthMargin;
9999
100+ @property (nonatomic ) BOOL isFullscreen;
101+
100102@end
101103
102104@implementation OSInAppMessageViewController
@@ -225,25 +227,27 @@ - (void)maxDisplayTimeTimerFinished {
225227
226228- (OSResultSuccessBlock)messageContentOnSuccess {
227229 return ^(NSDictionary *data) {
228- if (!data) {
229- [self encounteredErrorLoadingMessageContent: nil ];
230- return ;
231- }
232-
233- let message = [NSString stringWithFormat: @" In App Messaging htmlContent.html: %@ " , data[@" html" ]];
234- [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: message];
235-
236- if (!self.message .isPreview )
237- [[OneSignal sessionManager ] onInAppMessageReceived: self .message.messageId];
230+ [OneSignalHelper dispatch_async_on_main_queue: ^{
231+ if (!data) {
232+ [self encounteredErrorLoadingMessageContent: nil ];
233+ return ;
234+ }
235+
236+ let message = [NSString stringWithFormat: @" In App Messaging htmlContent.html: %@ " , data[@" html" ]];
237+ [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: message];
238+
239+ if (!self.message .isPreview )
240+ [[OneSignal sessionManager ] onInAppMessageReceived: self .message.messageId];
238241
239- let baseUrl = [NSURL URLWithString: OS_IAM_WEBVIEW_BASE_URL];
240- [self parseContentData: data];
241- if (self.waitForTags ) {
242- return ;
243- }
244- [self .delegate messageWillDisplay: self .message];
245- [self .messageView loadedHtmlContent: self .pendingHTMLContent withBaseURL: baseUrl];
246- self.pendingHTMLContent = nil ;
242+ let baseUrl = [NSURL URLWithString: OS_IAM_WEBVIEW_BASE_URL];
243+ [self parseContentData: data];
244+ if (self.waitForTags ) {
245+ return ;
246+ }
247+ [self .delegate messageWillDisplay: self .message];
248+ [self .messageView loadedHtmlContent: self .pendingHTMLContent withBaseURL: baseUrl];
249+ self.pendingHTMLContent = nil ;
250+ }];
247251 };
248252}
249253
@@ -261,6 +265,34 @@ - (void)parseContentData:(NSDictionary *)data {
261265 self.useWidthMargin = ![styles[@" remove_width_margin" ] boolValue ];
262266 }
263267 }
268+ self.isFullscreen = !self.useHeightMargin ;
269+ if (self.isFullscreen ) {
270+ self.pendingHTMLContent = [self setContentInsetsInHTML: self .pendingHTMLContent];
271+ }
272+ }
273+
274+ - (NSString *)setContentInsetsInHTML : (NSString *)html {
275+ NSMutableString *newHTML = [[NSMutableString alloc ] initWithString: html];
276+ if (@available (iOS 11 , *)) {
277+ UIWindow *keyWindow = UIApplication.sharedApplication .keyWindow ;
278+ CGFloat top = keyWindow.safeAreaInsets .top ;
279+ CGFloat bottom = keyWindow.safeAreaInsets .bottom ;
280+ CGFloat right = keyWindow.safeAreaInsets .right ;
281+ CGFloat left = keyWindow.safeAreaInsets .left ;
282+ NSString *safeAreaInsetsObjectString = [NSString stringWithFormat: @" {\n \
283+ top: %f ,\n \
284+ bottom: %f ,\n \
285+ right: %f ,\n \
286+ left: %f ,\n \
287+ }" ,top, bottom, right, left];
288+ // Script to set the tags for liquid tag substitution
289+ NSString *insetsString = [NSString stringWithFormat: @" \n\n \
290+ <script> \
291+ setSafeAreaInsets(%@ );\
292+ </script>" ,safeAreaInsetsObjectString];
293+ [newHTML appendString: insetsString];
294+ }
295+ return newHTML;
264296}
265297
266298- (void )setWaitForTags : (BOOL )waitForTags {
@@ -318,13 +350,15 @@ - (void)addConstraintsForMessage {
318350 // as a notch or a rounded corner on newer iOS devices like iPhone X
319351 // Note that Safe Area layout guides were only introduced in iOS 11
320352 if (@available (iOS 11 , *)) {
321- let safeArea = self.view .safeAreaLayoutGuide ;
322- top = safeArea.topAnchor ;
323- bottom = safeArea.bottomAnchor ;
324- leading = safeArea.leadingAnchor ;
325- trailing = safeArea.trailingAnchor ;
326- center = safeArea.centerXAnchor ;
327- height = safeArea.heightAnchor ;
353+ if (!self.isFullscreen ) {
354+ let safeArea = self.view .safeAreaLayoutGuide ;
355+ top = safeArea.topAnchor ;
356+ bottom = safeArea.bottomAnchor ;
357+ leading = safeArea.leadingAnchor ;
358+ trailing = safeArea.trailingAnchor ;
359+ center = safeArea.centerXAnchor ;
360+ height = safeArea.heightAnchor ;
361+ }
328362 }
329363
330364 CGRect mainBounds = [OneSignalViewHelper getScreenBounds ];
@@ -400,8 +434,10 @@ - (void)addConstraintsForMessage {
400434 self.view .window .frame = mainBounds;
401435 NSLayoutAnchor *centerYanchor = self.view .centerYAnchor ;
402436 if (@available (iOS 11 , *)) {
403- let safeArea = self.view .safeAreaLayoutGuide ;
404- centerYanchor = safeArea.centerYAnchor ;
437+ if (!self.isFullscreen ) {
438+ let safeArea = self.view .safeAreaLayoutGuide ;
439+ centerYanchor = safeArea.centerYAnchor ;
440+ }
405441 }
406442
407443 self.initialYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
@@ -670,6 +706,10 @@ - (BOOL)shouldDismissMessageWithPanGestureOffset:(double)offset withVelocity:(do
670706 }
671707}
672708
709+ - (void )updateSafeAreaInsets {
710+
711+ }
712+
673713/*
674714 This delegate function gets called when in-app html is load or action button is tapped
675715 */
@@ -701,6 +741,7 @@ - (void)jsEventOccurredWithBody:(NSData *)body {
701741 case OSInAppMessageBridgeEventTypePageResize: {
702742 // Unused resize event for IAM during actions like orientation changes and displaying an IAM
703743 // self.message.height = event.resize.height;
744+ [self updateSafeAreaInsets ];
704745 break ;
705746 }
706747 case OSInAppMessageBridgeEventTypeActionTaken: {
0 commit comments