Skip to content

Firebase Push Notifications not opening on iOS devices #2239

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
dev-catalyst opened this issue Mar 26, 2020 · 6 comments
Closed

Firebase Push Notifications not opening on iOS devices #2239

dev-catalyst opened this issue Mar 26, 2020 · 6 comments
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested.

Comments

@dev-catalyst
Copy link

dev-catalyst commented Mar 26, 2020

I have developed a flutter app and I am using Firebase cloud messaging for push notifications. I have done all the configuration for iOS device and I am receiving the push notifications as well but when I click on the notification it is not opening the respective screen on the app. Everything is working fine on Android. On notification click it opens the app screen but I am having trouble with iOS devices only.

Here is my flutter doctor output:

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en-IN)
    • Flutter version 1.12.13+hotfix.8 at /Users/riyabarua/development/flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/riyabarua/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.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)
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed
      instructions.

[✓] 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.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 21C3B3CA-BA43-45F3-9A49-28B9C29AABC0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

! Doctor found issues in 2 categories.

Here is my AppDelegate.swift code:

import UIKit
import Flutter
import GoogleMaps
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
  _ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
  GMSServices.provideAPIKey("AIzaSyA7WnMXO960l9OOt0znIfbRuEUThY2fnk0")
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
  GeneratedPluginRegistrant.register(with: self)
  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

I have also added the following code to Info.plist:

<key>FirebaseScreenReportingEnabled</key>
<true/>
<key>FirebaseAppDelegateProxyEnabled</key>
<true/>
@TahaTesser
Copy link

Hi @dev-catalyst

can you please provide your flutter doctor -v and flutter run --verbose?

Can you print onLaunch on iOS?

     print('run onLaunch');
     print('onLaunch: $message');

Related to #1619

Thank you

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Mar 27, 2020
@dev-catalyst
Copy link
Author

Hi @TahaTesser,

Output for flutter doctor -v:

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en-IN)
    • Flutter version 1.12.13+hotfix.8 at /Users/riyabarua/development/flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/riyabarua/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.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)
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.

[✓] 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.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 21C3B3CA-BA43-45F3-9A49-28B9C29AABC0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

! Doctor found issues in 2 categories.

Flutter run verbose output is in this google doc link - https://drive.google.com/file/d/1B23NjEfUqFgybXR4EZcOg_7y5WjVosYa/view?usp=sharing

onLaunch and onResume both events are not firing.

Please check it out and help with a solution.

@MaikuB
Copy link
Contributor

MaikuB commented Mar 29, 2020

@dev-catalyst what version of the plugin are you using? I believe the plugin may have a mistake around needing to modify AppDelegate. With version 6.0.13 onwards, this should only be needed when FirebaseAppDelegateProxyEnabled is set to false

@dev-catalyst
Copy link
Author

@MaikuB I'm using 6.0.13 version of the plugin. So, I don't need to modify AppDelegate at all if I don't set FirebaseAppDelegateProxyEnabled to false. But I also tried it this way and was still facing the same issue.

@MaikuB
Copy link
Contributor

MaikuB commented Mar 30, 2020

In that case I'm not sure what's is wrong there as it worked for me. I tested this but by modifying code I have at https://github.com/MaikuB/flutter_firebase_local_notifications_examples. After i removed all references to flutter_local_notifications and updated the pubspec file to point to the latest version of firebase_messaging and reverted the modification to the AppDelegate file, this was working fine. Perhaps you can do a comparison and see if there's something missing in your iOS app. Have you also turned on the remote notification capability (see https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app)?

@dev-catalyst
Copy link
Author

I was able to resolve this issue by making some changes in the Info.plist and AppDelegate.swift

I added this at the end of Info.plist

<key>FirebaseAppDelegateProxyEnabled</key>
<true/>

and this is my AppDelegate.swift after making some changes

import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
  _ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
  GeneratedPluginRegistrant.register(with: self)
  if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
  }
  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    @available(iOS 10.0, *)
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert,.sound,.badge])
    }
}

I also changed the way I was fetching the data in my notification handler to navigate to a particular screen

onResume: (Map<String, dynamic> message) async {
     if (Platform.isIOS) {
        _navigationService.navigateTo(
        routes.EventDetail,
           arguments: '${message["eventId"]}',
        );
      } else {
        _navigationService.navigateTo(
         routes.EventDetail,
           arguments: '${message["data"]["eventId"]}',
         );
      }
 },

@firebase firebase locked and limited conversation to collaborators Aug 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested.
Projects
None yet
Development

No branches or pull requests

3 participants