FIRIAMRenderingWindowHelper.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <TargetConditionals.h>
  17. #if TARGET_OS_IOS
  18. #import "FirebaseInAppMessaging/Sources/DefaultUI/Banner/FIRIAMBannerViewUIWindow.h"
  19. #import "FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMRenderingWindowHelper.h"
  20. @implementation FIRIAMRenderingWindowHelper
  21. + (UIWindow *)UIWindowForModalView {
  22. static UIWindow *UIWindowForModal;
  23. static dispatch_once_t onceToken;
  24. dispatch_once(&onceToken, ^{
  25. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  26. if (@available(iOS 13.0, *)) {
  27. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  28. UIWindowForModal = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  29. } else {
  30. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  31. UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  32. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  33. }
  34. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  35. UIWindowForModal.windowLevel = UIWindowLevelNormal;
  36. });
  37. return UIWindowForModal;
  38. }
  39. + (UIWindow *)UIWindowForBannerView {
  40. static UIWindow *UIWindowForBanner;
  41. static dispatch_once_t onceToken;
  42. dispatch_once(&onceToken, ^{
  43. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  44. if (@available(iOS 13.0, *)) {
  45. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  46. UIWindowForBanner = [[FIRIAMBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
  47. } else {
  48. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  49. UIWindowForBanner =
  50. [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  51. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  52. }
  53. #endif
  54. UIWindowForBanner.windowLevel = UIWindowLevelNormal;
  55. });
  56. return UIWindowForBanner;
  57. }
  58. + (UIWindow *)UIWindowForImageOnlyView {
  59. static UIWindow *UIWindowForImageOnly;
  60. static dispatch_once_t onceToken;
  61. dispatch_once(&onceToken, ^{
  62. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  63. if (@available(iOS 13.0, *)) {
  64. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  65. UIWindowForImageOnly = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  66. } else {
  67. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  68. UIWindowForImageOnly = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  69. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  70. }
  71. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  72. UIWindowForImageOnly.windowLevel = UIWindowLevelNormal;
  73. });
  74. return UIWindowForImageOnly;
  75. }
  76. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  77. + (UIWindowScene *)foregroundedScene API_AVAILABLE(ios(13.0)) {
  78. for (UIWindowScene *connectedScene in [UIApplication sharedApplication].connectedScenes) {
  79. if (connectedScene.activationState == UISceneActivationStateForegroundActive) {
  80. return connectedScene;
  81. }
  82. }
  83. return nil;
  84. }
  85. #endif
  86. @end
  87. #endif // TARGET_OS_IOS