Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[firebase_messaging] changing getToken to rely on platform's getToken (2) #869

Merged
merged 5 commits into from
Oct 30, 2018

Conversation

ffeu
Copy link
Contributor

@ffeu ffeu commented Oct 24, 2018

intends to fix flutter/flutter#17699 and fix flutter/flutter#20378

Removing local cache of getToken() in the dart part of the plugin. Now getToken() calls directly its counterparts in the iOS and Android implementations. This enables obtaining its value without calling configure() or having to wait for a new token refresh.

replaces PR #789

@Hixie

@philipgiuliani
@calebisstupid
@beardo01
@muirandy

@ffeu
Copy link
Contributor Author

ffeu commented Oct 24, 2018

I think the error in the checks is flutter/flutter#23095

@ffeu ffeu changed the title firebase_messaging: changing getToken to rely on platform's getToken (2) [firebase_messaging] changing getToken to rely on platform's getToken (2) Oct 25, 2018
@ffeu
Copy link
Contributor Author

ffeu commented Oct 25, 2018

Hi @Hixie
I think this one is ready, I recreated the PR from that other one.

Copy link
Contributor

@kroikie kroikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here. Looks good, would you mind using the Instance ID to retrieve the token on iOS as well? You are already doing so on Android, could you do the same on iOS?

@@ -74,6 +74,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
NSString *topic = call.arguments;
[[FIRMessaging messaging] unsubscribeFromTopic:topic];
result(nil);
} else if ([@"getToken" isEqualToString:method]) {
result([[FIRMessaging messaging] FCMToken]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the callback to retrieve the token from InstanceID in the same way it is done here:
https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/ViewController.m#L39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, but let me make a question first.

On Android, that was the only way I managed to make it work - I couldn't find a way to get it without a callback.

On iOS, in the example you sent, it seems the local token is accessed using the same way I'm currently using. And then it does what seems to be getting the remote token from Instance ID.

Wouldn't they have to be same ? Why would they differ?

I ask because I've made other changes (which I'm holding waiting for this PR) to allow token unregistration (deleteInstanceID, setAutoInitEnabled, etc), and if getting a remote token requests for a new one, it would interfere in the way I was thinking it works.

Copy link
Contributor

@kroikie kroikie Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token is automatically generated by the native SDKs however if you directly call getToken without the callback there is the possibility that it could be null. Using the callback would mean that getToken from the dart side either returns the cached token or returns the token when it becomes available but never null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HHmm, in this PR I'm removing the dart cached token value - I would rather use the Android and iOS cached values. If we managed to do that, I think getting a null would be understandable (if not previously configured), specially considering that it would be way faster.

However, if we can't do that on both (in Android it seems that currently there isn't a cached value - deprecated), then I agree it's better to have both obtaining it 'remotely'.

I'll make the change, but it will take some time to test the issues again!

Copy link
Contributor

@kroikie kroikie Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Instance ID does not always go remote for the token. If the token is available then the callback returns immediately so should be just as fast as if you called it directly. Also it would be good to have the same behaviour on both Android and iOS. Thanks a lot for looking into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kroikie,

Please take a look in the iOS an Android implementations. It's WIP as I didn't properly test them.

I changed the Android implementation from OnSuccessListener to OnCompleteListener to uniform implementations, logging the error if found.

Let me know if that's ok (then I'll test it) :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that looks good to me! Thanks!

@ffeu ffeu changed the title [firebase_messaging] changing getToken to rely on platform's getToken (2) [WIP] [firebase_messaging] changing getToken to rely on platform's getToken (2) Oct 26, 2018
@ffeu
Copy link
Contributor Author

ffeu commented Oct 29, 2018

Tested on:

  • Android Emulator
  • Android Real Device
  • iOS Simulator (fcm doesn't work, but getToken now does work!)
  • iOS Real Device

@ffeu ffeu changed the title [WIP] [firebase_messaging] changing getToken to rely on platform's getToken (2) [firebase_messaging] changing getToken to rely on platform's getToken (2) Oct 29, 2018
@ffeu
Copy link
Contributor Author

ffeu commented Oct 29, 2018

Hey @kroikie , I finished testing.
Let me know if anything else is needed.

Copy link
Contributor

@kroikie kroikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thank you!

@willvlad
Copy link

Why is this closed? It's not working for me on IOS real device.
Stable branch of Flutter 1.0, latest firebase_messaging 2.1.0, ios 12.1.2
configure placed above gettoken, yet still doesn't print any token from the iphone...

andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
… (2) (flutter#869)

* changing plugin getToken to call platforms getTokens (2nd PR)

* switching to get the token using callback and uniforming calls
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
… (2) (flutter#869)

* changing plugin getToken to call platforms getTokens (2nd PR)

* switching to get the token using callback and uniforming calls
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants