Skip to content

FCM callbacks are not fired #50936

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
locskot opened this issue Feb 17, 2020 · 4 comments
Closed

FCM callbacks are not fired #50936

locskot opened this issue Feb 17, 2020 · 4 comments

Comments

@locskot
Copy link

locskot commented Feb 17, 2020

firebase_core: ^0.4.4
firebase_analytics: ^5.0.11
firebase_crashlytics: ^0.1.2+5
firebase_remote_config: ^0.3.0+1
firebase_messaging: ^6.0.9

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15 19A602, locale ru-RU)
• Flutter version 1.12.13+hotfix.8 at /Users/locskot/dev/sdk/flutter
• Framework revision 0b8abb4 (6 days ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced
• Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/locskot/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.7.5

[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (2 available)
• iPhone (Iaroslav) • 6071e5eeasd38d6e1feb9asdd89a20cbb4f79442e6b34d • ios • iOS 13.1.3
• iPhone 11 Pro Max • 811B15EA-66E8-4F40-AD29-3E1482B32A4E • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

The code is the same.
The only onMessage fired on Simulator.
If the app is launched and in the background - onResume not triggered. When tap on app icon - app become visible and onMessage fired. Same for onLaunch callback. No system notification for both onLaunch and onResume callbacks.

For real device the only onLaunch fired. The device display system notification after receiving push. Tap on notification - the onLaunch code will execute If the app was not launched before. As expected, but another 2 callbacks do not work as expected.
Tap on notification - the onResume code will not execute If the app was launched before and staying in background (I used break points and logs). App just become visible and no more actions.
If app is launched and in foreground onMessage did not fired at all. But postman says messageId.

Below my postman push
{
"notification": {
"title": "New ride",
"body": "Great news",
},
"data": {
"trip_id" : "2057746",
}
"to": "eZ7iAktp3HY:APA91bHmKKTryWfk2Ux1xjxbYsGqPoOcmAp3ho_uDBcEu1YQS47LzYe_ZaG50Z-_Fw_K4tIMbeIIbgUwCDaYPaIDOODhmeJAJwnLf0-0xW9z2ocxsuTUD6eFiPeqH2YvgS8eG44STNMg"
}

Before updating flutter channel and packages in pubspec.yaml all callbacks (onMessage, onResume and onLaunch) working great.
Any ideas how to fix?

@locskot
Copy link
Author

locskot commented Feb 17, 2020

I also ran 'pod install' command in cd /users/user/dev/flutter/myapp/ios and saw in terminal's log:

Installing Firebase 6.17.0 (was 6.13.0)
Using FirebaseABTesting (3.1.2)
Installing FirebaseAnalytics 6.2.2 (was 6.1.6)
Installing FirebaseAnalyticsInterop 1.5.0 (was 1.4.0 and source changed to https://github.com/CocoaPods/Specs.git from https://cdn.cocoapods.org/)
Installing FirebaseCore 6.6.2 (was 6.4.0 and source changed to https://github.com/CocoaPods/Specs.git from https://cdn.cocoapods.org/)
Installing FirebaseCoreDiagnostics 1.2.0 (was 1.1.2)
Installing FirebaseCoreDiagnosticsInterop 1.2.0 (was 1.1.0)
Installing FirebaseInstallations (1.1.0)
Installing FirebaseInstanceID 4.3.1 (was 4.2.7 and source changed to https://github.com/CocoaPods/Specs.git from https://cdn.cocoapods.org/)
Installing FirebaseMessaging 4.2.1 (was 4.1.9)
Installing FirebaseRemoteConfig 4.4.7 (was 4.4.5)
Using Flutter (1.0.0)
Installing GoogleAppMeasurement 6.2.2 (was 6.1.6)
Installing GoogleDataTransport 4.0.0 (was 3.2.0)
Installing GoogleDataTransportCCTSupport 1.4.0 (was 1.2.2)
Installing GoogleUtilities 6.5.1 (was 6.3.2)
Installing PromisesObjC (1.2.8)
Installing Protobuf 3.11.4 (was 3.11.0)

@locskot
Copy link
Author

locskot commented Feb 18, 2020

firebase/flutterfire#1056 (comment)
After some changes in AppDelegate.swift all callbacks work as expected on a real device. On simulators without changes

Below complete AppDelegate.swift:

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure();
if #available(iOS 10.0, *) {
// UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
//
// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// UNUserNotificationCenter.current().requestAuthorization(
// options: authOptions,
// completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)

}
}

@locskot locskot closed this as completed Feb 18, 2020
@ravishankarsingh1996
Copy link

FirebaseExtended/flutterfire#1056 (comment)
After some changes in AppDelegate.swift all callbacks work as expected on a real device. On simulators without changes

Below complete AppDelegate.swift:

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure();
if #available(iOS 10.0, *) {
// UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
//
// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// UNUserNotificationCenter.current().requestAuthorization(
// options: authOptions,
// completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)

}
}

This one worked for me.
Thanks

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2021
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

2 participants