Skip to content
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

FIRMessagingRemoteNotificationsProxy updated to use GULAppDelegateSwizzler #2683

Merged
merged 31 commits into from Apr 4, 2019

Conversation

@maksymmalyhin
Copy link
Contributor

commented Mar 29, 2019

Changes required for #2591

  • GULAppDelegateSwizzler - remote notifications methods support
  • FIRMessagingRemoteNotificationsProxy - swizzling of Application delegate updated to use GULAppDelegateSwizzler

NOTE: FIRMessagingRemoteNotificationsProxy still swizzles UNUserNotificationDelegate methods in its own way. I think, we should refactor it as a separate PR once we finish refactoring of app delegate swizzling in all libraries.

maksymmalyhin added 21 commits Mar 26, 2019
Revert "FIRAuthAppDelegateProxy: implementation updated to use GULApp…
…DelegateSwizzler [WIP]"

This reverts commit b2eabf2.
FIRMessagingRemoteNotificationsProxy - AppDelegate proxy - test only …
…public interface with no assumptions on the implementation details
Merge branch 'master'
Conflicts:
	Example/Messaging/Tests/FIRMessagingRemoteNotificationsProxyTest.m
Cocoapods 1.6.1: Podfile supports only single post_install hook. It i…
…s applied to all targets. Move the hook to the top level to avoid confusion.
FIRMessagingRemoteNotificationsProxyTest: [GULAppDelegateSwizzler res…
…etProxyOriginalDelegateOnceToken] at the beginning of each test.
@@ -272,3 +261,14 @@ target 'InstanceID_Example_tvOS' do
end
end

# Set define to turn on GUL_UNSWIZZLING and GUL_APP_DELEGATE_TESTING for the unit tests
post_install do |installer_representation|

This comment has been minimized.

Copy link
@maksymmalyhin

maksymmalyhin Mar 29, 2019

Author Contributor

Now (Cocoapods 1.6.1) there is only post_install hook supported for entire Podfile. It affects all targets anyways, so I moved it to the upper level to avoid confusion.

This comment has been minimized.

Copy link
@tejasd

tejasd Apr 3, 2019

Collaborator

Cool, thanks!

@@ -376,6 +459,18 @@ + (void)createSubclassWithObject:(id<UIApplicationDelegate>)anObject {
}
objc_setAssociatedObject(anObject, &kGULOpenURLOptionsSourceAnnotationsIMPKey,
openURLSourceAppAnnotationIMPPointer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(anObject, &kGULRealDidRegisterForRemoteNotificationsIMPKey,

This comment has been minimized.

Copy link
@maksymmalyhin

maksymmalyhin Mar 29, 2019

Author Contributor

@tejasd I used the same way of storing the original implementations as for the old methods. But it looks like it can be optimized to avoid boilerplate (e.g. store the implementations in a dictionary).

Also, I think, some repeated code may be moved to separate methods.

@tejasd What do you think?

This comment has been minimized.

Copy link
@tejasd

tejasd Mar 30, 2019

Collaborator

Yup, that's definitely an option! Feel free to refactor that in a separate PR :)

@maksymmalyhin

This comment has been minimized.

Copy link
Contributor Author

commented Mar 29, 2019

@chliangGoogle I tested basic use-cases like receiving messages sent from the console. Are there any cases I need to pay a specific attention to.

@chliangGoogle

This comment has been minimized.

Copy link
Collaborator

commented Mar 29, 2019

Receiving messages are not enough for testing swizzling, if you look at the implementations, we swizzle because for a few reason. A. to be able to track analytics events, so would be great to check if Analytics is able to track notification_open or notification_foreground event; You can use the "debug mode" on Analytics console to see if a notification is opened or in foreground; B. when APNS token is updated, we need to notify FCM, so would be great if we can also make sure that logic is called. Basically we need to make sure all the "swizzled logic" is actually getting triggered. Does that make sense?


@interface FIRMessagingRemoteNotificationsProxy ()
@interface FIRMessagingRemoteNotificationsProxy () <UIApplicationDelegate>

This comment has been minimized.

Copy link
@chliangGoogle

chliangGoogle Mar 29, 2019

Collaborator

Is there an alternative than following this protocol? This makes macOS support very hard .

This comment has been minimized.

Copy link
@tejasd

tejasd Mar 30, 2019

Collaborator

Refer comment below.

This comment has been minimized.

Copy link
@maksymmalyhin

maksymmalyhin Apr 1, 2019

Author Contributor

@chliangGoogle Does FCM support MacOS now? If not, I can take care of MacOS support for GULAppDelegateSwizzler in a separate PR. What do you think?

This comment has been minimized.

Copy link
@paulb777

This comment has been minimized.

Copy link
@maksymmalyhin

maksymmalyhin Apr 1, 2019

Author Contributor

@paulb777 It looks like tvOS has no difference in the App Delegate, so supporting tvOS by GULAppDelegateSwizzler should be trivial. I'll update it in this PR

This comment has been minimized.

Copy link
@chliangGoogle

chliangGoogle Apr 2, 2019

Collaborator

Will we make GULAppDelegateSwizzler macOS support in this PR? If not, we can add a todo and fix in another PR.

This comment has been minimized.

Copy link
@maksymmalyhin

maksymmalyhin Apr 2, 2019

Author Contributor

I created a ticket for this #2706

@@ -466,39 +389,36 @@ id getNamedPropertyFromObject(id object, NSString *propertyName, Class klass) {
return property;
}

#pragma mark - Swizzled Methods
#pragma mark - UIApplicationDelegate

This comment has been minimized.

Copy link
@chliangGoogle

chliangGoogle Mar 29, 2019

Collaborator

@tejasd Is this required that if I use GULAppDelegateSwizzler and I need to swizzle some methods under UIApplicationDelegate, my class must follow the protocol and implement the methods here?

This comment has been minimized.

Copy link
@tejasd

tejasd Mar 30, 2019

Collaborator

With the current design, yes. If that's a blocker we can create our own protocol, say GULAppDelegate which can be platform agnostic.

@paulb777
Copy link
Member

left a comment

LGTM

Needs approval from @chliangGoogle

@chliangGoogle
Copy link
Collaborator

left a comment

LGTM on FCM part.

Also need approval from @tejasd


@interface FIRMessagingRemoteNotificationsProxy ()
@interface FIRMessagingRemoteNotificationsProxy () <UIApplicationDelegate>

This comment has been minimized.

Copy link
@chliangGoogle

chliangGoogle Apr 2, 2019

Collaborator

Will we make GULAppDelegateSwizzler macOS support in this PR? If not, we can add a todo and fix in another PR.

@tejasd
tejasd approved these changes Apr 3, 2019
@@ -107,6 +122,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
@end
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

@interface GULAppDelegateSwizzler (FIRMessagingRemoteNotificationsProxyTest)

This comment has been minimized.

Copy link
@tejasd

tejasd Apr 3, 2019

Collaborator

Consider importing the private header.

@@ -272,3 +261,14 @@ target 'InstanceID_Example_tvOS' do
end
end

# Set define to turn on GUL_UNSWIZZLING and GUL_APP_DELEGATE_TESTING for the unit tests
post_install do |installer_representation|

This comment has been minimized.

Copy link
@tejasd

tejasd Apr 3, 2019

Collaborator

Cool, thanks!

Merge branch 'master'
Conflicts:
	GoogleUtilities/AppDelegateSwizzler/GULAppDelegateSwizzler.m
	GoogleUtilities/Example/Tests/Swizzler/GULAppDelegateSwizzlerTest.m

@maksymmalyhin maksymmalyhin merged commit 267e9a6 into master Apr 4, 2019

2 checks passed

cla/google All necessary CLAs are signed
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@maksymmalyhin maksymmalyhin deleted the mm/messaging-swizzling branch Apr 4, 2019

@chliangGoogle

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2019

@maksymmalyhin Please make sure to test it with Analytics to ensure the notification tracking still works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.