GULAppDelegateSwizzler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2018 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 "GULApplication.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. typedef NSString *const GULAppDelegateInterceptorID;
  20. /** This class contains methods that isa swizzle the app delegate. */
  21. @interface GULAppDelegateSwizzler : NSProxy
  22. /** Registers an app delegate interceptor whose methods will be invoked as they're invoked on the
  23. * original app delegate.
  24. *
  25. * @param interceptor An instance of a class that conforms to the application delegate protocol.
  26. * The interceptor is NOT retained.
  27. * @return A unique GULAppDelegateInterceptorID if interceptor was successfully registered; nil
  28. * if it fails.
  29. */
  30. + (nullable GULAppDelegateInterceptorID)registerAppDelegateInterceptor:
  31. (id<GULApplicationDelegate>)interceptor;
  32. /** Unregisters an interceptor with the given ID if it exists.
  33. *
  34. * @param interceptorID The object that was generated when the interceptor was registered.
  35. */
  36. + (void)unregisterAppDelegateInterceptorWithID:(GULAppDelegateInterceptorID)interceptorID;
  37. /** This method ensures that the original app delegate has been proxied. Call this before
  38. * registering your interceptor. This method is safe to call multiple times (but it only proxies
  39. * the app delegate once).
  40. *
  41. * This method doesn't proxy APNS related methods:
  42. * @code
  43. * - application:didRegisterForRemoteNotificationsWithDeviceToken:
  44. * - application:didFailToRegisterForRemoteNotificationsWithError:
  45. * - application:didReceiveRemoteNotification:fetchCompletionHandler:
  46. * - application:didReceiveRemoteNotification:
  47. * @endcode
  48. *
  49. * To proxy these methods use +[GULAppDelegateSwizzler
  50. * proxyOriginalDelegateIncludingAPNSMethods]. The methods have to be proxied separately to
  51. * avoid potential warnings from Apple review about missing Push Notification Entitlement (e.g.
  52. * https://github.com/firebase/firebase-ios-sdk/issues/2807)
  53. *
  54. * The method has no effect for extensions.
  55. *
  56. * @see proxyOriginalDelegateIncludingAPNSMethods
  57. */
  58. + (void)proxyOriginalDelegate;
  59. /** This method ensures that the original app delegate has been proxied including APNS related
  60. * methods. Call this before registering your interceptor. This method is safe to call multiple
  61. * times (but it only proxies the app delegate once) or
  62. * after +[GULAppDelegateSwizzler proxyOriginalDelegate]
  63. *
  64. * This method calls +[GULAppDelegateSwizzler proxyOriginalDelegate] under the hood.
  65. * After calling this method the following App Delegate methods will be proxied in addition to
  66. * the methods proxied by proxyOriginalDelegate:
  67. * @code
  68. * - application:didRegisterForRemoteNotificationsWithDeviceToken:
  69. * - application:didFailToRegisterForRemoteNotificationsWithError:
  70. * - application:didReceiveRemoteNotification:fetchCompletionHandler:
  71. * - application:didReceiveRemoteNotification:
  72. * @endcode
  73. *
  74. * The method has no effect for extensions.
  75. *
  76. * @see proxyOriginalDelegate
  77. */
  78. + (void)proxyOriginalDelegateIncludingAPNSMethods;
  79. /** Indicates whether app delegate proxy is explicitly disabled or enabled. Enabled by default.
  80. *
  81. * @return YES if AppDelegateProxy is Enabled, NO otherwise.
  82. */
  83. + (BOOL)isAppDelegateProxyEnabled;
  84. /** Returns the current sharedApplication.
  85. *
  86. * @return the current application instance if in an app, or nil if in extension or if it doesn't
  87. * exist.
  88. */
  89. + (nullable GULApplication *)sharedApplication;
  90. /** Do not initialize this class. */
  91. - (instancetype)init NS_UNAVAILABLE;
  92. NS_ASSUME_NONNULL_END
  93. @end