GULSceneDelegateSwizzler.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2019 Google LLC
  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 <Foundation/Foundation.h>
  17. #import <TargetConditionals.h>
  18. #if !TARGET_OS_OSX
  19. #import <UIKit/UIKit.h>
  20. #endif // !TARGET_OS_OSX
  21. #if ((TARGET_OS_IOS || TARGET_OS_TV) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000))
  22. #define UISCENE_SUPPORTED 1
  23. #endif
  24. NS_ASSUME_NONNULL_BEGIN
  25. typedef NSString *const GULSceneDelegateInterceptorID;
  26. /** This class contains methods that isa swizzle the scene delegate. */
  27. @interface GULSceneDelegateSwizzler : NSProxy
  28. #if UISCENE_SUPPORTED
  29. /** Registers a scene delegate interceptor whose methods will be invoked as they're invoked on the
  30. * original scene delegate.
  31. *
  32. * @param interceptor An instance of a class that conforms to the application delegate protocol.
  33. * The interceptor is NOT retained.
  34. * @return A unique GULSceneDelegateInterceptorID if interceptor was successfully registered; nil
  35. * if it fails.
  36. */
  37. + (nullable GULSceneDelegateInterceptorID)registerSceneDelegateInterceptor:
  38. (id<UISceneDelegate>)interceptor API_AVAILABLE(ios(13.0), tvos(13.0));
  39. /** Unregisters an interceptor with the given ID if it exists.
  40. *
  41. * @param interceptorID The object that was generated when the interceptor was registered.
  42. */
  43. + (void)unregisterSceneDelegateInterceptorWithID:(GULSceneDelegateInterceptorID)interceptorID
  44. API_AVAILABLE(ios(13.0), tvos(13.0));
  45. /** Do not initialize this class. */
  46. - (instancetype)init NS_UNAVAILABLE;
  47. #endif // UISCENE_SUPPORTED
  48. /** This method ensures that the original scene delegate has been proxied. Call this before
  49. * registering your interceptor. This method is safe to call multiple times (but it only proxies
  50. * the scene delegate once).
  51. *
  52. * The method has no effect for extensions.
  53. */
  54. + (void)proxyOriginalSceneDelegate;
  55. /** Indicates whether scene delegate proxy is explicitly disabled or enabled. Enabled by default.
  56. *
  57. * @return YES if SceneDelegateProxy is Enabled, NO otherwise.
  58. */
  59. + (BOOL)isSceneDelegateProxyEnabled;
  60. @end
  61. NS_ASSUME_NONNULL_END