FIRIAMRenderingWindowHelper.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "FIRIAMRenderingWindowHelper.h"
  17. #import "FIRIAMBannerViewUIWindow.h"
  18. @implementation FIRIAMRenderingWindowHelper
  19. + (UIWindow *)UIWindowForModalView {
  20. static UIWindow *UIWindowForModal;
  21. static dispatch_once_t onceToken;
  22. dispatch_once(&onceToken, ^{
  23. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  24. if (@available(iOS 13.0, *)) {
  25. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  26. UIWindowForModal = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  27. } else {
  28. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  29. UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  30. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  31. }
  32. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  33. UIWindowForModal.windowLevel = UIWindowLevelNormal;
  34. });
  35. return UIWindowForModal;
  36. }
  37. + (UIWindow *)UIWindowForBannerView {
  38. static UIWindow *UIWindowForBanner;
  39. static dispatch_once_t onceToken;
  40. dispatch_once(&onceToken, ^{
  41. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  42. if (@available(iOS 13.0, *)) {
  43. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  44. UIWindowForBanner = [[FIRIAMBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
  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. + (UIWindow *)UIWindowForImageOnlyView {
  57. static UIWindow *UIWindowForImageOnly;
  58. static dispatch_once_t onceToken;
  59. dispatch_once(&onceToken, ^{
  60. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  61. if (@available(iOS 13.0, *)) {
  62. UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
  63. UIWindowForImageOnly = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  64. } else {
  65. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  66. UIWindowForImageOnly = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  67. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  68. }
  69. #endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  70. UIWindowForImageOnly.windowLevel = UIWindowLevelNormal;
  71. });
  72. return UIWindowForImageOnly;
  73. }
  74. #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  75. + (UIWindowScene *)foregroundedScene API_AVAILABLE(ios(13.0)) {
  76. for (UIWindowScene *connectedScene in [UIApplication sharedApplication].connectedScenes) {
  77. if (connectedScene.activationState == UISceneActivationStateForegroundActive) {
  78. return connectedScene;
  79. }
  80. }
  81. return nil;
  82. }
  83. #endif
  84. @end