FIRIAMRenderingWindowHelper.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #import "FirebaseInAppMessaging/Sources/Private/Util/UIApplication+FIRForegroundWindowScene.h"
  21. @implementation FIRIAMRenderingWindowHelper
  22. + (UIWindow *)windowForBlockingView {
  23. static UIWindow *UIWindowForModal;
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  27. if (@available(iOS 13.0, tvOS 13.0, *)) {
  28. UIWindowForModal = [[self class] iOS13PlusWindow];
  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 *)windowForNonBlockingView {
  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, tvOS 13.0, *)) {
  45. UIWindowForBanner = [[self class] iOS13PlusBannerWindow];
  46. } else {
  47. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  48. UIWindowForBanner =
  49. [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  50. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  51. }
  52. #endif
  53. UIWindowForBanner.windowLevel = UIWindowLevelNormal;
  54. });
  55. return UIWindowForBanner;
  56. }
  57. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  58. + (UIWindow *)iOS13PlusWindow API_AVAILABLE(ios(13.0)) {
  59. UIWindowScene *foregroundedScene = [[UIApplication sharedApplication] fir_foregroundWindowScene];
  60. if (foregroundedScene.delegate) {
  61. return [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  62. } else {
  63. return [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  64. }
  65. }
  66. + (FIRIAMBannerViewUIWindow *)iOS13PlusBannerWindow API_AVAILABLE(ios(13.0)) {
  67. UIWindowScene *foregroundedScene = [[UIApplication sharedApplication] fir_foregroundWindowScene];
  68. if (foregroundedScene.delegate) {
  69. return [[FIRIAMBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
  70. } else {
  71. return [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  72. }
  73. }
  74. #endif
  75. @end
  76. #endif // TARGET_OS_IOS