Skip to content

Commit b049b6d

Browse files
authored
Merge pull request #437 from Countly/fix_bad_access_to_key_window
fix: unresponsive while returning from external link
2 parents 20d1f1a + f9c3772 commit b049b6d

7 files changed

Lines changed: 75 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 25.4.10
2+
* Mitigated an issue when returning from the external content link.
3+
14
## 25.4.9
25
* Added a new config option disableViewRestartForManualRecording to disable auto close/restart behavior of manual views on app background/foreground actions.
36
* Added a new config option "setWebviewDisplayOption: WebViewDisplayOption" to control how Content and Feedback Widgets are presented.

Countly-PL.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly-PL'
3-
s.version = '25.4.9'
3+
s.version = '25.4.10'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly'
3-
s.version = '25.4.9'
3+
s.version = '25.4.10'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@
808808
"@loader_path/Frameworks",
809809
);
810810
MACOSX_DEPLOYMENT_TARGET = 10.14;
811-
MARKETING_VERSION = 25.4.9;
811+
MARKETING_VERSION = 25.4.10;
812812
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
813813
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
814814
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -840,7 +840,7 @@
840840
"@loader_path/Frameworks",
841841
);
842842
MACOSX_DEPLOYMENT_TARGET = 10.14;
843-
MARKETING_VERSION = 25.4.9;
843+
MARKETING_VERSION = 25.4.10;
844844
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
845845
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
846846
PROVISIONING_PROFILE_SPECIFIER = "";

CountlyCommon.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ @interface CountlyCommon ()
2929
#endif
3030
@end
3131

32-
NSString* const kCountlySDKVersion = @"25.4.9";
32+
NSString* const kCountlySDKVersion = @"25.4.10";
3333
NSString* const kCountlySDKName = @"objc-native-ios";
3434

3535
NSString* const kCountlyErrorDomain = @"ly.count.ErrorDomain";

CountlyTests/TestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestUtils {
1313
static let commonDeviceId: String = "deviceId"
1414
static let commonAppKey: String = "appkey"
1515
static let host: String = "https://testing.count.ly/"
16-
static let SDK_VERSION = "25.4.9"
16+
static let SDK_VERSION = "25.4.10"
1717
static let SDK_NAME = "objc-native-ios"
1818

1919
static func cleanup() -> Void {

CountlyWebViewController.m

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
#if (TARGET_OS_IOS)
1212
@implementation CountlyWebViewController
13+
{
14+
UIStatusBarStyle _cachedStatusBarStyle;
15+
BOOL _hasCachedStatusBarStyle;
16+
}
1317
- (BOOL)prefersStatusBarHidden
1418
{
1519
return CountlyContentBuilderInternal.sharedInstance.webViewDisplayOption == IMMERSIVE ? YES : NO;
@@ -22,33 +26,88 @@ - (BOOL)prefersHomeIndicatorAutoHidden
2226

2327
- (UIStatusBarStyle)preferredStatusBarStyle
2428
{
25-
return UIApplication.sharedApplication.keyWindow.rootViewController.preferredStatusBarStyle;
29+
if (_hasCachedStatusBarStyle) {
30+
return _cachedStatusBarStyle;
31+
}
32+
33+
UIWindow *keyWindow = [self getKeyWindow];
34+
35+
if (keyWindow && keyWindow.rootViewController) {
36+
_cachedStatusBarStyle = keyWindow.rootViewController.preferredStatusBarStyle;
37+
_hasCachedStatusBarStyle = YES;
38+
return _cachedStatusBarStyle;
39+
}
40+
41+
return UIStatusBarStyleLightContent;
2642
}
2743

2844
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
2945
{
3046
return UIInterfaceOrientationMaskAll;
3147
}
3248

49+
- (UIWindow *)getKeyWindow {
50+
if (@available(iOS 13.0, *)) {
51+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
52+
if (![scene isKindOfClass:[UIWindowScene class]]) {
53+
continue;
54+
}
55+
56+
UIWindowScene *windowScene = (UIWindowScene *)scene;
57+
58+
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
59+
for (UIWindow *window in windowScene.windows) {
60+
if (window.isKeyWindow) {
61+
return window;
62+
}
63+
}
64+
}
65+
}
66+
} else {
67+
return UIApplication.sharedApplication.keyWindow;
68+
}
69+
70+
return nil;
71+
}
72+
3373
- (BOOL)shouldAutorotate
3474
{
3575
return YES;
3676
}
3777

3878
- (void)loadView
3979
{
40-
self.view = [[TouchDelegatingView alloc] initWithFrame:UIApplication.sharedApplication.keyWindow.rootViewController.view.bounds];
80+
UIWindow *keyWindow = [self getKeyWindow];
81+
CGRect bounds = keyWindow.rootViewController.view.bounds;
82+
83+
if (CGRectIsEmpty(bounds)) {
84+
bounds = UIScreen.mainScreen.bounds;
85+
}
86+
87+
self.view = [[TouchDelegatingView alloc] initWithFrame:bounds];
4188
}
4289

4390
- (void)viewDidLoad
4491
{
4592
[super viewDidLoad];
93+
94+
UIWindow *keyWindow = [self getKeyWindow];
95+
96+
if (!_hasCachedStatusBarStyle) {
97+
if (keyWindow && keyWindow.rootViewController) {
98+
_cachedStatusBarStyle = keyWindow.rootViewController.preferredStatusBarStyle;
99+
_hasCachedStatusBarStyle = YES;
100+
}
101+
}
46102

47-
if ([self.view isKindOfClass:[TouchDelegatingView class]])
48-
{
49-
TouchDelegatingView *delegatingView = (TouchDelegatingView *)self.view;
50-
delegatingView.touchDelegate = UIApplication.sharedApplication.keyWindow.rootViewController.view;
51-
}
103+
104+
if ([self.view isKindOfClass:[TouchDelegatingView class]])
105+
{
106+
TouchDelegatingView *delegatingView = (TouchDelegatingView *)self.view;
107+
if (keyWindow && keyWindow.rootViewController) {
108+
delegatingView.touchDelegate = keyWindow.rootViewController.view;
109+
}
110+
}
52111

53112
// Fully transparent controller background
54113
self.view.backgroundColor = [UIColor clearColor];

0 commit comments

Comments
 (0)