Skip to content

[firebase_messaging] iOS Push Notification not Received in Notification tray #2941

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

Closed
kalpesh opened this issue Jul 13, 2020 · 3 comments
Closed

Comments

@kalpesh
Copy link

kalpesh commented Jul 13, 2020

iOS Push Notification not Received in Notification tray (when app is Not running or in Background) Received when app is launched.

Followed all the steps to integrate firebase_messaging 6.0.16 into our Flutter Application.

PFB Flutter Code

@override
  void initState() {
    super.initState();
    //for android
    mainpref = SPManager();
    // With this, we will be able to check if the permission is granted or not
    // when returning to the application
    WidgetsBinding.instance.addObserver(this);
    // With this, we will be able to check if the permission is granted or not
    // when returning to the application

    if (Platform.isIOS) {
      iOSPermission();
    }
    configLocalNotification();

    fcm.getToken().then((token) {
      FLog.debug(
          className: this.runtimeType.toString(), text: 'token : ' + token);
      mainpref.setNotificationToken(token);
    });

    fcm.configure(
      onMessage: (Map<String, dynamic> message) async {
        FLog.info(text: "onMessage: $message");
        showNotification(message);
      },
      onLaunch: (Map<String, dynamic> message) async {
        FLog.info(text: "onLaunch: $message");
        var tag =
            Platform.isIOS ? message['screen'] : message['data']['screen'];
        var data = Platform.isIOS ? message : message['data'];
        Utility().isLaunchedViaNotification = true;
        callPage(tag, data);
      },
      onResume: (Map<String, dynamic> message) async {
        FLog.info(text: "onResume: $message");
        var tag =
            Platform.isIOS ? message['screen'] : message['data']['screen'];
        var data = Platform.isIOS ? message : message['data'];
        callPage(tag, data);
      },
    );
  }

void iOSPermission() {
    //Needed by iOS only
    fcm.requestNotificationPermissions(const IosNotificationSettings(
        sound: true, badge: true, alert: true, provisional: false));
    fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
      mainpref.setalert(settings.alert);
      mainpref.setsound(settings.sound);
      mainpref.setbadge(settings.badge);
      FLog.info(text: "Settings registered: $settings");
    });
  }

iOS Code

import UIKit
import Flutter
import Firebase
import flutter_downloader

@UIApplicationMain

@objc class AppDelegate: FlutterAppDelegate {
  
  override func application(
    _ application: UIApplication,
    
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure();
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    
    FlutterDownloaderPlugin.setPluginRegistrantCallback { (registry) in
        if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
            FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
        }
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    override func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
        completionHandler();
    }
}

To Reproduce
Steps to reproduce the behavior:

  1. Sending the Push Notification using FCM Rest API. (https://fcm.googleapis.com/fcm/send)

Expected behavior
Notification should be received in notification tray when app is not running or app is in background.

Flutter doctor

[flutter] flutter doctor -v
[✓] Flutter (Channel beta, 1.19.0-4.3.pre, on Mac OS X 10.15.4 19E287, locale en-IN)
    • Flutter version 1.19.0-4.3.pre at /Users/iosdev/flutter sdk/flutter
    • Framework revision 8fe7655ed2 (12 days ago), 2020-07-01 14:31:18 -0700
    • Engine revision 9a28c3bcf4
    • Dart version 2.9.0 (build 2.9.0-14.1.beta)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/iosdev/Library/Android/sdk
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2.1, Build version 11B53
    • CocoaPods version 1.9.0.beta.2

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

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

[✓] Connected device (2 available)
    • Air 2         • ***************************************************** • ios • iOS 13.5.1
    • iPhone 11 Pro • 9E3AE2F3-278E-4B2F-A466-4BF78F9B335E     • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-2 (simulator)

! Doctor found issues in 1 category.
exit code 0

Please help me in this issue.

Thanks

@kalpesh kalpesh changed the title [<FIREBASE_PRODUCT>] <TITLE> iOS Push Notification not Received in Notification tray [<FIREBASE_PRODUCT>] <iOS Push Notification not Received in Notification tray> Jul 13, 2020
@kalpesh kalpesh changed the title [<FIREBASE_PRODUCT>] <iOS Push Notification not Received in Notification tray> [firebase_messaging] iOS Push Notification not Received in Notification tray Jul 13, 2020
@jfrsbg
Copy link

jfrsbg commented Jul 13, 2020

I'm facing de same issue by now, Android works fine but iOS doesn't. There are various workarrounds of December and January on github with this same issue but nothing is working for me. I've configured everything that the docs are saying but I'm only receiving notifications with the app in foreground

@FernandoUFS
Copy link

FernandoUFS commented Jul 13, 2020

I am facing the same problem, maybe you can try this #2854 (comment)

@TahaTesser
Copy link

TahaTesser commented Jul 14, 2020

Closing as duplicate of #2854

@firebase firebase locked and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants