FIRIAMRenderingWindowHelper.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 *)windowForBlockingView {
  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, tvOS 13.0, *)) {
  27. UIWindowForModal = [[self class] iOS13PlusWindow];
  28. } else {
  29. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  30. UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  31. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  32. }
  33. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  34. UIWindowForModal.windowLevel = UIWindowLevelNormal;
  35. });
  36. return UIWindowForModal;
  37. }
  38. + (UIWindow *)windowForNonBlockingView {
  39. static UIWindow *UIWindowForBanner;
  40. static dispatch_once_t onceToken;
  41. dispatch_once(&onceToken, ^{
  42. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  43. if (@available(iOS 13.0, tvOS 13.0, *)) {
  44. UIWindowForBanner = [[self class] iOS13PlusBannerWindow];
  45. } else {
  46. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  47. UIWindowForBanner =
  48. [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  49. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  50. }
  51. #endif
  52. UIWindowForBanner.windowLevel = UIWindowLevelNormal;
  53. });
  54. return UIWindowForBanner;
  55. }
  56. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  57. + (UIWindowScene *)foregroundedScene API_AVAILABLE(ios(13.0)) {
  58. for (UIWindowScene *connectedScene in [UIApplication sharedApplication].connectedScenes) {
  59. if (connectedScene.activationState == UISceneActivationStateForegroundActive) {
  60. return connectedScene;
  61. }
  62. }
  63. return nil;
  64. }
  65. + (UIWindow *)iOS13PlusWindow API_AVAILABLE(ios(13.0)) {
  66. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  67. if (foregroundedScene.delegate) {
  68. return [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  69. } else {
  70. return [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  71. }
  72. }
  73. + (FIRIAMBannerViewUIWindow *)iOS13PlusBannerWindow API_AVAILABLE(ios(13.0)) {
  74. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  75. if (foregroundedScene.delegate) {
  76. return [[FIRIAMBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
  77. } else {
  78. return [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  79. }
  80. }
  81. #endif
  82. @end
  83. #endif // TARGET_OS_IOS