@@ -48,7 +48,7 @@ - (void)enterContentZone:(NSArray<NSString *> *)tags {
4848 return ;
4949
5050 if (_requestTimer != nil ) {
51- CLY_LOG_I (@" Already entered for content zone, please exit from content zone first to start again" );
51+ CLY_LOG_I (@" %s , Already entered for content zone, please exit from content zone first to start again" , __FUNCTION__ );
5252 return ;
5353 }
5454
@@ -97,7 +97,7 @@ - (void)fetchContents {
9797
9898 NSURLSessionTask *dataTask = [[NSURLSession sharedSession ] dataTaskWithRequest: [self fetchContentsRequest ] completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
9999 if (error) {
100- CLY_LOG_I (@" Fetch content details failed: %@ " , error);
100+ CLY_LOG_I (@" %s , Fetch content details failed: %@ " , __FUNCTION__ , error);
101101 self->_isRequestQueueLocked = NO ;
102102 return ;
103103 }
@@ -106,13 +106,13 @@ - (void)fetchContents {
106106 NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &jsonError];
107107
108108 if (jsonError) {
109- CLY_LOG_I (@" Failed to parse JSON: %@ " , jsonError);
109+ CLY_LOG_I (@" %s , Failed to parse JSON: %@ " , __FUNCTION__ , jsonError);
110110 self->_isRequestQueueLocked = NO ;
111111 return ;
112112 }
113113
114114 if (!jsonResponse) {
115- CLY_LOG_I (@" Received empty or null response." );
115+ CLY_LOG_I (@" %s , Received empty or null response." , __FUNCTION__ );
116116 self->_isRequestQueueLocked = NO ;
117117 return ;
118118 }
@@ -152,30 +152,38 @@ - (NSURLRequest *)fetchContentsRequest
152152}
153153
154154- (CGSize)getWindowSize {
155- CGSize size = CGSizeZero ;
155+ UIWindow *window = nil ;
156156
157- // Attempt to retrieve the size from the connected scenes (for modern apps)
158157 if (@available (iOS 13.0 , *)) {
159- NSSet <UIScene *> *scenes = [[UIApplication sharedApplication ] connectedScenes ];
160- for (UIScene *scene in scenes) {
158+ for (UIScene *scene in [UIApplication sharedApplication ].connectedScenes ) {
161159 if ([scene isKindOfClass: [UIWindowScene class ]]) {
162- UIWindowScene *windowScene = (UIWindowScene *)scene;
163- UIWindow *window = windowScene.windows .firstObject ;
164- if (window) {
165- size = window.bounds .size ;
166- return size; // Return immediately if we find a valid size
167- }
160+ window = ((UIWindowScene *)scene).windows .firstObject ;
161+ break ;
168162 }
169163 }
164+ } else {
165+ window = [[UIApplication sharedApplication ].delegate window ];
170166 }
171167
172- // Fallback for legacy apps using AppDelegate
173- id <UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication ] delegate ];
174- if ([appDelegate respondsToSelector: @selector (window )]) {
175- UIWindow *legacyWindow = [appDelegate performSelector: @selector (window )];
176- if (legacyWindow) {
177- size = legacyWindow.bounds .size ;
178- }
168+ if (!window) return CGSizeZero;
169+
170+ UIEdgeInsets safeArea = UIEdgeInsetsZero;
171+ CGFloat screenScale = [UIScreen mainScreen ].scale ;
172+ if (@available (iOS 11.0 , *)) {
173+ safeArea = window.safeAreaInsets ;
174+ safeArea.left /= screenScale;
175+ safeArea.bottom /= screenScale;
176+ safeArea.right /= screenScale;
177+ }
178+
179+ UIInterfaceOrientation orientation = [UIApplication sharedApplication ].statusBarOrientation ;
180+ BOOL isLandscape = UIInterfaceOrientationIsLandscape (orientation);
181+
182+ CGSize size = CGSizeMake (window.bounds .size .width , window.bounds .size .height );
183+
184+ if (!isLandscape){
185+ size.width -= safeArea.left + safeArea.right ;
186+ size.height -= safeArea.top + safeArea.bottom ;
179187 }
180188
181189 return size;
@@ -196,6 +204,8 @@ - (NSString *)resolutionJson {
196204 @" landscape" : @{@" height" : @(lHpW), @" width" : @(lWpH)}
197205 };
198206
207+ CLY_LOG_D (@" %s , %@ " , __FUNCTION__, resolutionDict);
208+
199209 NSData *jsonData = [NSJSONSerialization dataWithJSONObject: resolutionDict options: 0 error: nil ];
200210 return [[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
201211}
@@ -205,7 +215,7 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi
205215 NSURL *url = [NSURL URLWithString: urlString];
206216
207217 if (!url || !url.scheme || !url.host ) {
208- NSLog (@" The URL is not valid: %@ " , urlString);
218+ CLY_LOG_E (@" %s , The URL is not valid: %@ " , __FUNCTION__ , urlString);
209219 return ;
210220 }
211221
@@ -227,17 +237,17 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi
227237 CGRect frame = CGRectMake (x, y, width, height);
228238
229239 // Log the URL and the frame
230- CLY_LOG_I (@" Showing content from URL: %@ " , url);
231- CLY_LOG_I (@" Placement frame: %@ " , NSStringFromCGRect(frame));
240+ CLY_LOG_I (@" %s , Showing content from URL: %@ " , __FUNCTION__ , url);
241+ CLY_LOG_I (@" %s , Placement frame: %@ " , __FUNCTION__ , NSStringFromCGRect(frame));
232242
233243 CountlyWebViewManager* webViewManager = CountlyWebViewManager.new ;
234244 [webViewManager createWebViewWithURL: url frame: frame appearBlock: ^
235245 {
236- CLY_LOG_I (@" Webview appeared" );
246+ CLY_LOG_I (@" %s , Webview appeared" , __FUNCTION__ );
237247 [self clearContentState ];
238248 } dismissBlock: ^
239249 {
240- CLY_LOG_I (@" Webview dismissed" );
250+ CLY_LOG_I (@" %s , Webview dismissed" , __FUNCTION__ );
241251 self->_minuteTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0
242252 target: self
243253 selector: @selector (enterContentZone )
0 commit comments