@@ -244,14 +244,7 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
244244 [[OneSignal sessionManager ] onInAppMessageReceived: self .message.messageId];
245245
246246 let baseUrl = [NSURL URLWithString: OS_IAM_WEBVIEW_BASE_URL];
247- NSMutableDictionary *fakeData = [[NSMutableDictionary alloc ] initWithDictionary: data];
248- fakeData[@" styles" ] = @{
249- @" top_margin" : @" 0" ,
250- @" bottom_margin" : @" 0" ,
251- @" left_margin" : @" 0" ,
252- @" right_margin" : @" 0" ,
253- };
254- [self parseContentData: fakeData];
247+ [self parseContentData: data];
255248 if (self.waitForTags ) {
256249 return ;
257250 }
@@ -263,20 +256,21 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
263256- (void )parseContentData : (NSDictionary *)data {
264257 self.pendingHTMLContent = data[@" html" ];
265258 self.maxDisplayTime = [data[@" display_duration" ] doubleValue ];
266- if (data[@" styles" ]) {
259+ NSDictionary *styles = data[@" styles" ];
260+ if (styles) {
267261 // We are currently only allowing default margin or no margin.
268262 // If we receive a number that isn't 0 we want to use default margin for now.
269- if (data[ @" styles" ] [@" top_margin" ]) {
270- self.topMarginModifier = [data[ @" styles" ] [@" top_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
263+ if (styles[@" top_margin" ]) {
264+ self.topMarginModifier = [styles[@" top_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
271265 }
272- if (data[ @" styles" ] [@" bottom_margin" ]) {
273- self.bottomMarginModifier = [data[ @" styles" ] [@" bottom_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
266+ if (styles[@" bottom_margin" ]) {
267+ self.bottomMarginModifier = [styles[@" bottom_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
274268 }
275- if (data[ @" styles" ] [@" left_margin" ]) {
276- self.leftMarginModifier = [data[ @" styles" ] [@" left_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
269+ if (styles[@" left_margin" ]) {
270+ self.leftMarginModifier = [styles[@" left_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
277271 }
278- if (data[ @" styles" ] [@" right_margin" ]) {
279- self.rightMarginModifier = [data[ @" styles" ] [@" right_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
272+ if (styles[@" right_margin" ]) {
273+ self.rightMarginModifier = [styles[@" right_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
280274 }
281275 }
282276}
@@ -411,10 +405,15 @@ - (void)addConstraintsForMessage {
411405 case OSInAppMessageDisplayPositionFullScreen:
412406 case OSInAppMessageDisplayPositionCenterModal:
413407 self.view .window .frame = mainBounds;
408+ NSLayoutAnchor *centerYanchor = self.view .centerYAnchor ;
409+ if (@available (iOS 11 , *)) {
410+ let safeArea = self.view .safeAreaLayoutGuide ;
411+ centerYanchor = safeArea.centerYAnchor ;
412+ }
414413
415- self.initialYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
416- self.finalYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
417- self.panVerticalConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
414+ self.initialYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
415+ self.finalYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
416+ self.panVerticalConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
418417 self.messageView .transform = CGAffineTransformMakeScale (0 , 0 );
419418 break ;
420419 }
0 commit comments