2 * Copyright 2018 Google LLC
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #import <Foundation/Foundation.h>
19 @protocol UIApplicationDelegate;
21 NS_ASSUME_NONNULL_BEGIN
23 typedef NSString *const GULAppDelegateInterceptorID;
25 /** This class contains methods that isa swizzle the app delegate. */
26 @interface GULAppDelegateSwizzler : NSProxy
28 /** Registers an app delegate interceptor whose methods will be invoked as they're invoked on the
29 * original app delegate.
31 * @param interceptor An instance of a class that conforms to the UIApplicationDelegate protocol.
32 * The interceptor is NOT retained.
33 * @return A unique GULAppDelegateInterceptorID if interceptor was successfully registered; nil
36 + (nullable GULAppDelegateInterceptorID)registerAppDelegateInterceptor:
37 (id<UIApplicationDelegate>)interceptor;
39 /** Unregisters an interceptor with the given ID if it exists.
41 * @param interceptorID The object that was generated when the interceptor was registered.
43 + (void)unregisterAppDelegateInterceptorWithID:(GULAppDelegateInterceptorID)interceptorID;
45 /** This method ensures that the original app delegate has been proxied. Call this before
46 * registering your interceptor. This method is safe to call multiple times (but it only proxies
47 * the app delegate once).
49 + (void)proxyOriginalDelegate NS_EXTENSION_UNAVAILABLE(
50 "App delegate proxy doesn't support extensions.");
52 /** Indicates whether app delegate proxy is explicitly disabled or enabled. Enabled by default.
54 * @return YES if AppDelegateProxy is Enabled, NO otherwise.
56 + (BOOL)isAppDelegateProxyEnabled;
58 /** Do not initialize this class. */
59 - (instancetype)init NS_UNAVAILABLE;