@@ -29,7 +29,7 @@ - (instancetype)init
2929{
3030 if (self = [super init ])
3131 {
32- self.requestInterval = 30.0 ;
32+ self.zoneTimerInterval = 30.0 ;
3333 _requestTimer = nil ;
3434 }
3535
@@ -55,7 +55,7 @@ - (void)enterContentZone:(NSArray<NSString *> *)tags {
5555 self.currentTags = tags;
5656
5757 [self fetchContents ];;
58- _requestTimer = [NSTimer scheduledTimerWithTimeInterval: self .requestInterval
58+ _requestTimer = [NSTimer scheduledTimerWithTimeInterval: self .zoneTimerInterval
5959 target: self
6060 selector: @selector (fetchContents )
6161 userInfo: nil
@@ -151,30 +151,49 @@ - (NSURLRequest *)fetchContentsRequest
151151 return request;
152152}
153153
154- - (NSString *)resolutionJson {
155- // TODO: check why area is not clickable and safearea things
156- CGRect screenBounds = [UIScreen mainScreen ].bounds ;
157- if (@available (iOS 11.0 , *)) {
158- CGFloat top = UIApplication.sharedApplication .keyWindow .safeAreaInsets .top ;
159-
160- if (top) {
161- screenBounds.origin .y += top + 5 ;
162- screenBounds.size .height -= top + 5 ;
163- } else {
164- screenBounds.origin .y += 20.0 ;
165- screenBounds.size .height -= 20.0 ;
154+ - (CGSize)getWindowSize {
155+ CGSize size = CGSizeZero;
156+
157+ // Attempt to retrieve the size from the connected scenes (for modern apps)
158+ if (@available (iOS 13.0 , *)) {
159+ NSSet <UIScene *> *scenes = [[UIApplication sharedApplication ] connectedScenes ];
160+ for (UIScene *scene in scenes) {
161+ 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+ }
168+ }
169+ }
170+ }
171+
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 ;
166178 }
167- } else {
168- screenBounds.origin .y += 20.0 ;
169- screenBounds.size .height -= 20.0 ;
170179 }
180+
181+ return size;
182+ }
183+
184+ - (NSString *)resolutionJson {
185+ // TODO: check why area is not clickable and safearea things
186+ CGSize size = [self getWindowSize ];
171187
172- CGFloat width = screenBounds.size .width ;
173- CGFloat height = screenBounds.size .height ;
188+ UIInterfaceOrientation orientation = [UIApplication sharedApplication ].statusBarOrientation ;
189+ BOOL isLandscape = UIInterfaceOrientationIsLandscape (orientation);
190+
191+ CGFloat lHpW = isLandscape ? size.height : size.width ;
192+ CGFloat lWpH = isLandscape ? size.width : size.height ;
174193
175194 NSDictionary *resolutionDict = @{
176- @" portrait" : @{@" height" : @(height ), @" width" : @(width )},
177- @" landscape" : @{@" height" : @(width ), @" width" : @(height )}
195+ @" portrait" : @{@" height" : @(lWpH ), @" width" : @(lHpW )},
196+ @" landscape" : @{@" height" : @(lHpW ), @" width" : @(lWpH )}
178197 };
179198
180199 NSData *jsonData = [NSJSONSerialization dataWithJSONObject: resolutionDict options: 0 error: nil ];
0 commit comments