From 620ea539dea76bb61a8d43a687800cc7f947b690 Mon Sep 17 00:00:00 2001 From: Ray Graham Date: Wed, 25 Oct 2023 09:19:50 -0700 Subject: [PATCH] HB-6642: update usage of getting screen scale on iOS17+ --- .../iOS/ChartboostMediationUnityBridge.mm | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/com.chartboost.mediation/Runtime/Plugins/iOS/ChartboostMediationUnityBridge.mm b/com.chartboost.mediation/Runtime/Plugins/iOS/ChartboostMediationUnityBridge.mm index 06b4967a..6e9485f6 100644 --- a/com.chartboost.mediation/Runtime/Plugins/iOS/ChartboostMediationUnityBridge.mm +++ b/com.chartboost.mediation/Runtime/Plugins/iOS/ChartboostMediationUnityBridge.mm @@ -616,7 +616,27 @@ void _chartboostMediationSetUserIdentifier(const char * userIdentifier) } float _chartboostMediationGetUIScaleFactor() { - // TODO: https://github.com/ChartBoost/ios-helium-sdk/pull/1314 + // `UIScreen.main` was deprecated in iOS 16. Apple doc: + // https://developer.apple.com/documentation/uikit/uiscreen/1617815-main + // Since `UIScreen.main` has been working correctly at least up to iOS 16, the custom + // implementation only targets iOS 17+, not iOS 13+. + if (@available(iOS 17.0, *)) { + NSSet *connectedScenes = UIApplication.sharedApplication.connectedScenes; + NSArray *activationStates = @[@(UISceneActivationStateForegroundActive), @(UISceneActivationStateForegroundInactive), @(UISceneActivationStateBackground), @(UISceneActivationStateUnattached)]; + for (NSNumber *activationState in activationStates) { + UISceneActivationState state = (UISceneActivationState)activationState.integerValue; + for (UIScene* connectedScene in connectedScenes) { + UIWindowScene *windowScene = (UIWindowScene*)connectedScene; + if (windowScene) { + if (windowScene.activationState == state) { + return windowScene.screen.scale; + } + } + } + } + } + + // fallback return UIScreen.mainScreen.scale; }