-
Notifications
You must be signed in to change notification settings - Fork 26
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
Got APNs Device Token even before the app launches #12
Comments
still couldn't get
|
Hey @kukat, this probably happens because your app receives the APNs token before your that widget builds, and that time, listener in that widget hasn't been set up yet? You can either:
Let me know if that makes sense. Sorry for the late reply, I've been a bit busy 🙏 |
Ahh, @kukat I just looked at this again and found in the docs: // To be informed that the device's token has been updated by the operating system
// You should update your servers with this token
Push.instance.onNewToken.listen((token) {
print("Just got a new FCM registration token: ${token}");
}); This doesn't include the first one. Not very intuitive, but this means whenever that is called, you should call your backend APIs to update the token. Otherwise this function would be called everytime the app is started. I thought of a couple of approaches:1. Minimal calls to
|
Turns out Android does approach 1, so I will use the same to be consistent. |
the APNs device token is printed even before the
initState
method.debug console:
and
Push.instance.onNewToken.listen
is never get executed.main.dart:
class _MyHomePageState extends State<MyHomePage> { StreamSubscription<String>? onNewTokenSubscription; @override void initState() { print("initState"); super.initState(); onNewTokenSubscription = Push.instance.onNewToken.listen((token) { - print("Just got a new push notification registration token: ${token}"); }); } @override void dispose() { onNewTokenSubscription?.cancel(); super.dispose(); } void afterUserLogin() async { final isGranted = await Push.instance.requestPermission(); } ...
The text was updated successfully, but these errors were encountered: