Comments (6)
Thank you for PR, we'll look at your changes but there are different development processes in our team so at this time we can't merge your PR directly, thank you @KholofeloMoyaba for your contribution 🍻
from hms-flutter-plugin.
By examining the logs, I can say that you are able to get the token from the server (0 result code means success). Are you listening the EventChannel that emits this token ? The plugin's example project displays a demo on this, the code is shown below:
String _token = '';
static const EventChannel TokenEventChannel = EventChannel(Channel.TOKEN_CHANNEL);
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
if (!mounted) return;
TokenEventChannel.receiveBroadcastStream()
.listen(_onTokenEvent, onError: _onTokenError);
}
void _onTokenEvent(Object event) {
setState(() {
_token = event;
});
showResult("TokenEvent", event);
}
void _onTokenError(Object error) {
setState(() {
_token = error;
});
showResult("TokenEvent", error);
}
If you are unable to obtain the token even after listening the TokenEventChannel, can you provide us with more details ?
- Huawei Push Kit Plugin version on pubspec.yaml
- Output from
flutter doctor
command - EMUI Version
from hms-flutter-plugin.
Hi @atavci
Thanks for the guidance. Adding the token event channel does work.
However, it still confuses me.
My understanding is that listening to TokenEventChannel
stream is for listening to any changes on the token channel retrospectively.
What I'm trying to do, however, is request the token on demand. Push.getToken
has a method signature as follows: Future<String> getToken()
. So I'm expecting this method to return the token on demand - outside of subscribing to the event channel.
For example, I may need specific hooks where I need to get the token at that point. So I would expect to Push.getToken
and get a value.
from hms-flutter-plugin.
I looked through the plugin source code and I see the issue.
The issue is that the android code for handling the getToken method doesn't accept the MethodChannel.Result object to pass the result back to flutter. It does, however, trigger the token event channel. This, in my opinion, is incorrect - or at least inconsistent behaviour. If the intent isn't for Push.getToken
to return the token value, then the method should be updated accordingly (e.g. it should return void) and documented properly.
Here is a link to the part of the code that's the culprit.
https://github.com/HMS-Core/hms-flutter-plugin/blob/master/flutter-hms-push/android/src/main/java/com/huawei/hms/flutter/push/hms/FlutterHmsInstanceId.java#L65
I can make a PR to fix this if you would allow that.
from hms-flutter-plugin.
Hi @KholofeloMoyaba ;
First of all, thank you very much for your concerns,
While we were developing the plugin, we paid special attention to support EMUI 10 and lower versions. Because;
If the EMUI version is 10.0 or later on a Huawei device, a token will be returned through the getToken method. If the getToken method fails to be called, Huawei Push Kit automatically caches the token request and calls the method again. A token will then be returned through the onNewToken method.
If the EMUI version on a Huawei device is earlier than 10.0 and no token is returned using the getToken method, a token will be returned using the onNewToken method.
But as you pointed out, that section has escaped from attention. Actually it's okay, we can get token with listening "TOKEN_CHANNEL" as it is, we'll fix the return type in our next version.
Thanks again @KholofeloMoyaba for your interest ~
from hms-flutter-plugin.
Hi again @aktug
Thanks for your response. Yes, I think the issue which is problematic on my side is just the communication back to flutter via the MethodChannel.Result
. I don't have an issue with anything EMUI related.
I've already made and tested a fix which would make it much easier for other Flutter developers. I don't have the rights to make a PR directly against this repo, so I made a fork. Please see below the PR from the forked repo:
#7
I have already tested this on a flutter app running on a Huawei device and it works, while still respecting the TOKEN_CHANNEL
. So nothing is lost.
Just to give you an example of how it becomes an issue on the flutter side using the current version:
- You basically have a request to
getToken
and you won't know within the same context if you got a reply or not. - You then have to listen to the
TOKEN_CHANNEL
in another part of the code and put it in some sort of persistent storage. - Finally, in the original
getToken
you need to add artificial delay and check the persistent storage to see if you have a result or not.
So it's possible, but it becomes very hard to have an on-demand implementation of getting a token on Flutter. The PR I supplied fixes this while keeping the TOKEN_CHANNEL
intact.
from hms-flutter-plugin.
Related Issues (20)
- Error 11203(3002): Service Unavailable when Starting Speech Recognition
- [huawei_push] Can't get the token: 907135003: client api invalid HOT 1
- NullPointerException in FlutterBackgroundRunner
- huawei_modeling3d 1.8.0+300 只支持Android平台, 近期有计划增加支持iOS等其他平台吗
- Location Kit throws AGC_CHECK_FAIL - 10808 (AppGallery Connect identity verification failed) HOT 2
- flutter ios AGConnectCrashPlugin init failed HOT 1
- AGP8 upgrade
- CRITICAL : the future initFusedLocationService() never end HOT 9
- huawei_push GetToken returned null HOT 5
- [Huawei_push][Bug] cancelNotificationsWithId is not await or return any result
- Flutter Huawei FIDO: unable to decode FIDO registration response
- 集成huawei_location 提示FusedLocationService is not initialized HOT 2
- Huawei analytics does not work on Flutter HOT 1
- Unexpected CFBundleExecutable Key
- Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
- UserHandle data is missing in Flutter FIDO Authentication result HOT 5
- Geocoding Service Error
- [huawei_map] Clicking on Marker Causes setZIndex:Failure win parameter HOT 1
- 有无支持基于鸿蒙的Flutter适配的计划
- Getting MissingPluginException when using with Huawei Location inside workmanager HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hms-flutter-plugin.