-
Notifications
You must be signed in to change notification settings - Fork 66
Adding MulticastAppDelegate #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ad1401f
add GULMulticastAppDelegate class and SwiftUISample test app
charlotteliang 038688c
simplify the code
charlotteliang 253da8a
make it multiplatform
charlotteliang 7c6dbc9
adjust the multicast app delegate to work with auth and messaging
charlotteliang 769da7f
remove the sample app
charlotteliang 05e0b8b
adjust the init method in multicast
charlotteliang cda176f
fix the issue that callback must implement to avoid crash
charlotteliang afebcb3
start depending on AppDelegateSwizzler
charlotteliang b3b013b
remove swift version
charlotteliang 812295f
rename the podspec and fix a few places based on the comments
charlotteliang e8fee5b
fix a few api names
charlotteliang 1158a7d
fix test breakage
charlotteliang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| Pod::Spec.new do |s| | ||
| # TODO: Is `GoogleMulticastAppDelegate` name fine? | ||
| s.name = 'GoogleMulticastAppDelegate' | ||
| s.version = '7.7.0' | ||
| s.summary = 'GoogleMulticastAppDelegate' | ||
|
|
||
| s.description = <<-DESC | ||
| GoogleMulticastAppDelegate | ||
| DESC | ||
|
|
||
| s.homepage = 'https://github.com/google/GoogleUtilities' | ||
| s.license = { :type => 'Apache', :file => 'LICENSE' } | ||
| s.authors = 'Google, Inc.' | ||
|
|
||
| s.source = { | ||
| :git => 'https://github.com/google/GoogleUtilities.git', | ||
| :tag => 'MulticastAppDelegate-' + s.version.to_s | ||
| } | ||
|
|
||
| ios_deployment_target = '9.0' | ||
| osx_deployment_target = '10.12' | ||
| tvos_deployment_target = '10.0' | ||
| watchos_deployment_target = '6.0' | ||
|
|
||
| s.ios.deployment_target = ios_deployment_target | ||
| # s.osx.deployment_target = osx_deployment_target | ||
| # s.tvos.deployment_target = tvos_deployment_target | ||
| # s.watchos.deployment_target = watchos_deployment_target | ||
|
|
||
| s.swift_versions = ['5.0', '5.2'] | ||
|
charlotteliang marked this conversation as resolved.
Outdated
|
||
|
|
||
| s.cocoapods_version = '>= 1.4.0' | ||
| s.prefix_header_file = false | ||
|
|
||
| s.pod_target_xcconfig = { | ||
| 'GCC_C_LANGUAGE_STANDARD' => 'c99', | ||
| 'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"', | ||
| } | ||
|
|
||
| base_dir = "GoogleMulticastAppDelegate/" | ||
| s.source_files = [ | ||
| base_dir + 'Sources/**/*.[hm]', | ||
| ] | ||
|
|
||
| s.dependency 'GoogleUtilities/AppDelegateSwizzler', '~> 7.7' | ||
|
|
||
| # s.test_spec 'unit' do |unit_tests| | ||
| # unit_tests.scheme = { :code_coverage => true } | ||
| # unit_tests.platforms = { | ||
| # :ios => ios_deployment_target, | ||
| # :osx => osx_deployment_target, | ||
| # :tvos => tvos_deployment_target | ||
| # } | ||
| # unit_tests.source_files = [ | ||
| # base_dir + 'Tests/Unit/**/*.[mh]', | ||
| # ] | ||
| # unit_tests.requires_app_host = true | ||
| # unit_tests.dependency 'OCMock' | ||
| # end | ||
|
|
||
| # s.test_spec 'unit-swift' do |unit_tests_swift| | ||
| # unit_tests_swift.scheme = { :code_coverage => true } | ||
| # unit_tests_swift.platforms = { | ||
| # :ios => ios_deployment_target, | ||
| # :osx => osx_deployment_target, | ||
| # :tvos => tvos_deployment_target | ||
| # } | ||
| # unit_tests_swift.source_files = [ | ||
| # base_dir + 'Tests/Unit/**/*.swift', | ||
| # ] | ||
|
|
||
| # unit_tests_swift.requires_app_host = true | ||
| # end | ||
| end | ||
155 changes: 155 additions & 0 deletions
155
GoogleMulticastAppDelegate/Sources/GULMulticastAppDelegate.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #import "GoogleMulticastAppDelegate/Sources/Public/GoogleUtilities/GULMulticastAppDelegate.h" | ||
|
|
||
| @interface GULMulticastAppDelegate () <GULMulticastAppDelegateProtocol> { | ||
| NSMutableArray<id> *_interceptors; | ||
| id<GULApplicationDelegate> _defaultAppDelegate; | ||
| } | ||
|
ncooke3 marked this conversation as resolved.
|
||
| @end | ||
|
|
||
| @implementation GULMulticastAppDelegate | ||
|
|
||
| - (instancetype)init { | ||
| self = [super init]; | ||
| if (self) { | ||
| _interceptors = [[NSMutableArray alloc] init]; | ||
|
ncooke3 marked this conversation as resolved.
|
||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (instancetype)initWithAppDelegate:(id<GULApplicationDelegate>)delegate { | ||
| self = [super init]; | ||
| if (self) { | ||
| _interceptors = [[NSMutableArray alloc] init]; | ||
| [_interceptors addObject:delegate]; | ||
|
charlotteliang marked this conversation as resolved.
Outdated
|
||
| _defaultAppDelegate = delegate; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| + (id<GULMulticastAppDelegateProtocol>)multicastDelegate { | ||
|
ncooke3 marked this conversation as resolved.
|
||
| id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate; | ||
| if (!appDelegate) { | ||
| return nil; | ||
| } | ||
| if ([appDelegate conformsToProtocol:@protocol(GULMulticastAppDelegateProtocol)]) { | ||
| id<GULMulticastAppDelegateProtocol> multicastAppDelegate = | ||
| (id<GULMulticastAppDelegateProtocol>)appDelegate; | ||
| return multicastAppDelegate; | ||
| } | ||
| if (appDelegate && [appDelegate respondsToSelector:@selector(getMulticastDelegate)]) { | ||
|
charlotteliang marked this conversation as resolved.
Outdated
|
||
| id<GULMulticastAppDelegateProtocol> multicastDelegate = | ||
| [appDelegate performSelector:@selector(getMulticastDelegate)]; | ||
| CFRetain((__bridge CFTypeRef)(multicastDelegate)); | ||
|
ncooke3 marked this conversation as resolved.
|
||
| return multicastDelegate; | ||
| } | ||
| return nil; | ||
| } | ||
|
|
||
| - (id<GULMulticastAppDelegateProtocol>)getMulticastDelegate { | ||
| return self; | ||
| } | ||
|
|
||
| - (void)addInterceptorWithDelegate:(id<GULApplicationDelegate>)interceptor { | ||
| [_interceptors addObject:interceptor]; | ||
| } | ||
|
|
||
| - (void)removeInterceptorWithDelegate:(id<GULApplicationDelegate>)interceptor { | ||
| [_interceptors removeObject:interceptor]; | ||
| } | ||
|
|
||
| - (BOOL)respondsToSelector:(SEL)aSelector { | ||
| if ([[self class] instancesRespondToSelector:aSelector]) { | ||
| return YES; | ||
| } | ||
| for (id<GULApplicationDelegate> interceptor in _interceptors) { | ||
| if (interceptor && [interceptor respondsToSelector:aSelector]) { | ||
| return YES; | ||
| } | ||
| } | ||
|
ncooke3 marked this conversation as resolved.
|
||
| return NO; | ||
| } | ||
|
|
||
| - (void)setDefaultAppDelegate:(id<UIApplicationDelegate>)defaultAppDelegate { | ||
| [_interceptors addObject:defaultAppDelegate]; | ||
| _defaultAppDelegate = defaultAppDelegate; | ||
| } | ||
|
|
||
| - (id)forwardingTargetForSelector:(SEL)aSelector { | ||
| return _defaultAppDelegate; | ||
| } | ||
|
|
||
| #if !TARGET_OS_WATCH | ||
| #pragma mark - Open URL | ||
| - (BOOL)application:(GULApplication *)app | ||
| openURL:(NSURL *)url | ||
| options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { | ||
| BOOL result = NO; | ||
| for (id<UIApplicationDelegate> interceptor in _interceptors) { | ||
| result = result || [interceptor application:app openURL:url options:options]; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| #pragma mark - APNS methods | ||
| - (void)application:(GULApplication *)application | ||
| didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | ||
| for (id<GULApplicationDelegate> interceptor in _interceptors) { | ||
| if ([interceptor respondsToSelector:@selector(application: | ||
| didRegisterForRemoteNotificationsWithDeviceToken:)]) { | ||
| [interceptor application:application | ||
| didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #else // !TARGET_OS_WATCH | ||
| - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | ||
| for (id<GULApplicationDelegate> interceptor in _interceptors) { | ||
| if ([interceptor | ||
| respondsToSelector:@selector(didRegisterForRemoteNotificationsWithDeviceToken)]) { | ||
| [interceptor didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; | ||
| } | ||
| } | ||
| } | ||
| #endif // !TARGET_OS_WATCH | ||
|
|
||
| #if TARGET_OS_IOS || TARGET_OS_TV | ||
|
charlotteliang marked this conversation as resolved.
Outdated
|
||
| - (void)application:(GULApplication *)application | ||
| didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { | ||
| for (id<GULApplicationDelegate> interceptor in _interceptors) { | ||
| if ([interceptor respondsToSelector:@selector(application: | ||
| didFailToRegisterForRemoteNotificationsWithError:)]) { | ||
| [interceptor application:application didFailToRegisterForRemoteNotificationsWithError:error]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void)application:(GULApplication *)application | ||
| didReceiveRemoteNotification:(NSDictionary *)userInfo | ||
| fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { | ||
| for (id<GULApplicationDelegate> interceptor in _interceptors) { | ||
| if ([interceptor respondsToSelector:@selector | ||
| (application:didReceiveRemoteNotification:fetchCompletionHandler:)]) { | ||
| [interceptor application:application | ||
| didReceiveRemoteNotification:userInfo | ||
| fetchCompletionHandler:completionHandler]; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| @end | ||
40 changes: 40 additions & 0 deletions
40
GoogleMulticastAppDelegate/Sources/Public/GoogleUtilities/GULMulticastAppDelegate.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| #import <GoogleUtilities/GULApplication.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @protocol GULMulticastAppDelegateProtocol <NSObject> | ||
|
|
||
| - (void)addInterceptorWithDelegate:(id<GULApplicationDelegate>)interceptor; | ||
|
|
||
| - (void)removeInterceptorWithDelegate:(id<GULApplicationDelegate>)interceptor; | ||
|
ncooke3 marked this conversation as resolved.
Outdated
|
||
|
|
||
| @end | ||
|
|
||
| @interface GULMulticastAppDelegate : NSObject <GULApplicationDelegate> | ||
|
|
||
| @property(nonatomic, copy) id<GULApplicationDelegate> defaultAppDelegate; | ||
|
charlotteliang marked this conversation as resolved.
|
||
|
|
||
| - (instancetype)initWithAppDelegate:(id<GULApplicationDelegate>)delegate; | ||
|
|
||
| - (void)addInterceptorWithDelegate:(id<GULApplicationDelegate>)delegate; | ||
|
|
||
| + (id<GULMulticastAppDelegateProtocol>)multicastDelegate; | ||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.