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

🐛 [FIREBASE_MESSAGING] OnTokenRefresh stream dont't work using iOS physical device/Emulator. #8122

Closed
yamauchieduardo opened this issue Feb 18, 2022 · 5 comments · Fixed by #8166
Assignees
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@yamauchieduardo
Copy link

When a new token is generate by the methods deleteToken and getToken, the stream onTokenRefresh doesn't call the
callback registered.

await FirebaseMessaging.instance.deleteToken();
await FirebaseMessaging.instance.getToken();

This behaviour just occurs using iOS physical device/Emulator, using Android physical device/Emulator work regularly.

 /// Fires when a new FCM token is generated.
  Stream<String> get onTokenRefresh {
    return _delegate.onTokenRefresh;
  }
Android example rendered

android

iOS example rendered

Simulator Screen Recording - iPhone 13 - 2022-02-18 at 14 59 53

Code to reproduce the bug:

import "dart:async";
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import "package:flutter/material.dart";

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(WidgetThatShowTheToken());
}

class WidgetThatShowTheToken extends StatefulWidget {
  @override
  _WidgetThatShowTheTokenState createState() => _WidgetThatShowTheTokenState();
}

class _WidgetThatShowTheTokenState extends State<WidgetThatShowTheToken> {
  //
  void setTokenSubscriptionStream() {
    tokenSubscriptionStream = FirebaseMessaging.instance.onTokenRefresh.listen(
          (String _token) {
        print("NEW TOKEN: $_token");
        setState(() => token = _token);
      },
    );
  }

  late StreamSubscription<String> tokenSubscriptionStream;

  String token = "NO TOKEN";

  @override
  void initState() {
    setTokenSubscriptionStream();
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    tokenSubscriptionStream.cancel();
  }

  Future<void> refreshToken() async {
    await FirebaseMessaging.instance.deleteToken();
    await FirebaseMessaging.instance.getToken();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("Platform: " + Platform.operatingSystem, style: const TextStyle(fontSize: 24)),
              const SizedBox(height: 16),
              Text(token, style: const TextStyle(fontSize: 10)),
              const SizedBox(height: 16),
              MaterialButton(
                color: Colors.blue,
                child: const Text("Refresh Token"),
                onPressed: refreshToken,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

To clarify: the methods getToken & deleteToken work as expected, just the stream onTokenRefresh don't work in iOS emulator/physical device.

@yamauchieduardo yamauchieduardo added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Feb 18, 2022
@yamauchieduardo yamauchieduardo changed the title 🐛 [FIREBASE_MESSAGING] OnTokenRefresh stream dont't work using iOS physical/Emulator. 🐛 [FIREBASE_MESSAGING] OnTokenRefresh stream dont't work using iOS physical device/Emulator. Feb 18, 2022
@darshankawar darshankawar added the triage Issue is currently being triaged. label Feb 21, 2022
@darshankawar
Copy link

@yamauchieduardo
Can you provide your flutter doctor -v and plugin version ? A similar / related issue was fixed that you can check : #5389

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Feb 21, 2022
@yamauchieduardo
Copy link
Author

yamauchieduardo commented Feb 21, 2022

Is similar with #5389, but still happen just for iOS physical device/Emulator.

Version used:
firebase_messaging: ^11.2.6

[✓] Flutter (Channel stable, 2.10.1, on macOS 12.1 21C52 darwin-arm, locale en-US)
    • Flutter version 2.10.1 at /Users/Yamauchi/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db747aa133 (12 days ago), 2022-02-09 13:57:35 -0600
    • Engine revision ab46186b24
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
    • Android SDK at /Users/Yamauchi/Library/Android/sdk
    • Platform android-32, build-tools 33.0.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] Connected device (2 available)
    • iPhone 13 (mobile) • 01DA1979-623D-4642-BE93-021F103A385B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 98.0.4758.102

[✓] HTTP Host Availability
    • All required HTTP hosts are available

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Feb 21, 2022
@WilkoThomassen
Copy link

WilkoThomassen commented Feb 22, 2022

I can confirm this issue. Before I migrated my project to null-safety, and updated the firebase packages it was working but now it doesn't. Version used ^11.2.6 but also tried to downgrade to 11.2.0, 10.0.9 and 10.0.0 but on all versions it still didn't work anymore.

The firebase_core package was upgraded from 1.2.0 to 1.12.0

sdk went from '>=2.7.0 <3.0.0' to '>=2.12.0 <3.0.0'

It is working properly on Android devices

flutter doctor -v:

Flutter (Channel stable, 2.10.0, on macOS 12.0.1 21A559 darwin-arm, locale en-NL)
    • Flutter version 2.10.0 at /Users/wilkothomassen/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (3 weeks ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/wilkothomassen/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (3 available)
    • sdk gphone arm64 (mobile) • emulator-5554             • android-arm64  • Android 11 (API 30) (emulator)
    • Wilko’s iPhone (mobile)   • 00008020-000B24203C30003A • ios            • iOS 15.2.1 19C63
    • Chrome (web)              • chrome                    • web-javascript • Google Chrome 98.0.4758.102

[✓] HTTP Host Availability
    • All required HTTP hosts are available

@darshankawar
Copy link

Thanks for the update. I do see the same behavior upon running the given code sample and running it on iOS simulator.

Screenshot 2022-02-22 at 5 00 51 PM

[✓] Flutter (Channel stable, 2.10.2, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
[✓] Chrome - develop for the web
[✓] VS Code (version 1.62.0)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.

@darshankawar darshankawar added platform: ios Issues / PRs which are specifically for iOS. plugin: messaging and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Feb 22, 2022
@darshankawar
Copy link

Related / similar: #5389

/cc @russellwheatley

@russellwheatley russellwheatley self-assigned this Feb 22, 2022
@darshankawar darshankawar added the resolution: fixed A fix has been merged or is pending merge from a PR. label Feb 28, 2022
@firebase firebase locked and limited conversation to collaborators Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
5 participants