@@ -48,7 +48,7 @@ - (void)enterContentZone:(NSArray<NSString *> *)tags {
48
48
return ;
49
49
50
50
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__ );
52
52
return ;
53
53
}
54
54
@@ -97,7 +97,7 @@ - (void)fetchContents {
97
97
98
98
NSURLSessionTask *dataTask = [[NSURLSession sharedSession ] dataTaskWithRequest: [self fetchContentsRequest ] completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
99
99
if (error) {
100
- CLY_LOG_I (@" Fetch content details failed: %@ " , error);
100
+ CLY_LOG_I (@" %s , Fetch content details failed: %@ " , __FUNCTION__ , error);
101
101
self->_isRequestQueueLocked = NO ;
102
102
return ;
103
103
}
@@ -106,13 +106,13 @@ - (void)fetchContents {
106
106
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &jsonError];
107
107
108
108
if (jsonError) {
109
- CLY_LOG_I (@" Failed to parse JSON: %@ " , jsonError);
109
+ CLY_LOG_I (@" %s , Failed to parse JSON: %@ " , __FUNCTION__ , jsonError);
110
110
self->_isRequestQueueLocked = NO ;
111
111
return ;
112
112
}
113
113
114
114
if (!jsonResponse) {
115
- CLY_LOG_I (@" Received empty or null response." );
115
+ CLY_LOG_I (@" %s , Received empty or null response." , __FUNCTION__ );
116
116
self->_isRequestQueueLocked = NO ;
117
117
return ;
118
118
}
@@ -152,30 +152,38 @@ - (NSURLRequest *)fetchContentsRequest
152
152
}
153
153
154
154
- (CGSize)getWindowSize {
155
- CGSize size = CGSizeZero ;
155
+ UIWindow *window = nil ;
156
156
157
- // Attempt to retrieve the size from the connected scenes (for modern apps)
158
157
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 ) {
161
159
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 ;
168
162
}
169
163
}
164
+ } else {
165
+ window = [[UIApplication sharedApplication ].delegate window ];
170
166
}
171
167
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 ;
179
187
}
180
188
181
189
return size;
@@ -196,6 +204,8 @@ - (NSString *)resolutionJson {
196
204
@" landscape" : @{@" height" : @(lHpW), @" width" : @(lWpH)}
197
205
};
198
206
207
+ CLY_LOG_D (@" %s , %@ " , __FUNCTION__, resolutionDict);
208
+
199
209
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: resolutionDict options: 0 error: nil ];
200
210
return [[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
201
211
}
@@ -205,7 +215,7 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi
205
215
NSURL *url = [NSURL URLWithString: urlString];
206
216
207
217
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);
209
219
return ;
210
220
}
211
221
@@ -227,17 +237,17 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi
227
237
CGRect frame = CGRectMake (x, y, width, height);
228
238
229
239
// 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));
232
242
233
243
CountlyWebViewManager* webViewManager = CountlyWebViewManager.new ;
234
244
[webViewManager createWebViewWithURL: url frame: frame appearBlock: ^
235
245
{
236
- CLY_LOG_I (@" Webview appeared" );
246
+ CLY_LOG_I (@" %s , Webview appeared" , __FUNCTION__ );
237
247
[self clearContentState ];
238
248
} dismissBlock: ^
239
249
{
240
- CLY_LOG_I (@" Webview dismissed" );
250
+ CLY_LOG_I (@" %s , Webview dismissed" , __FUNCTION__ );
241
251
self->_minuteTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0
242
252
target: self
243
253
selector: @selector (enterContentZone )
0 commit comments