Flutter Push notification not displaying on IOS
Asked Answered
P

4

22

I am having an issue with Flutter and IOS in regards to Push notifications.

My setup and things that work:

1) I installed the firebase_messaging: ^5.1.6 package with no errors / followed all their instructions for IOS

2) I have asked user permission on IOS and accepted to receive push notifications

3) I am able to get an FCM token on IOS & Android devices

4) I have created a Key in the Apple developer section and added the key to FCM

5) I have closed the app / sent it to the background when testing - still no luck

6) I have added the google-service-info file to Runner using Xcode

7) I have added push notifications and background notifications in XCode Capabilities

8) I am testing on an iPhone 7 physical device, and a physical iPad

I have used curl to send a notification to an IOS device

curl -X POST --header "Authorization: key=<myAuthKEY>" \
    --Header "Content-Type: application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d "{\"to\":\"<myDeviceKey>\",\"notification\":{\"body\":\"Hello\"},\"priority\":10}"

I get a success response from firebase

{"multicast_id":<SomeIdHere>,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"<SomeIdHere>"}]}

Here is how I retrieve the token:

firebaseMessaging.getToken().then((String token) {
      _authModel.setNotificationToken(token);
    });

When I run the app on IOS, I do not get any Firebase errors.

I've been messing around with this for 2 days now, so it's getting a bit annoying, all the above seems to work on Android.

Any suggestions, please.

Flutter Doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.15 19A583, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.38.1)
[✓] Connected device (4 available)

• No issues found!

My AppDelegate.m file

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [FIRApp configure];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

Papillary answered 9/10, 2019 at 8:53 Comment(6)
I think it is related to FirebaseAppDelegateProxyEnabled. medium.com/flutterpub/… This link will be helpful.Godman
The link seems off, the archive one is still active: web.archive.org/web/20191118225834/https://medium.com/… but without images :(Wrought
This one seems good as well: medium.com/@jun.chenying/…Wrought
Are you able to send them using the firebase messaging console?Wrought
@user3057745 Do you resolve this issue?Sastruga
Anyone resolved it. Facing the issue :(Epizoic
H
3

It's not pretty, you may need to provide a lot more details, but please file this issue to https://github.com/FirebaseExtended/flutterfire/issues. Otherwise, a quick search of iOS push notification issues shows variety of reports. Here are some similar ones, maybe one is related yours?

Or if you already filed one, share the link! Others may add feedback to yours.

Hierogram answered 24/2, 2020 at 23:42 Comment(0)
Z
1

You have to complete all the steps from https://pub.dev/packages/firebase_messaging carefully. I was also stuck in it. But later I realized am missing something. Then I recheck all the steps. I missed registering with APN(Apple Push Notification).So please recheck once again.

Zap answered 28/3, 2020 at 3:15 Comment(1)
Can you please elaborate what you missed and how its fixed?Vexation
D
0

I faced the same issue and I followed the official guide of flutter fire but it is unfortunate that it has not provided certain necessary steps of iOS configuration which I found somewhere else.

I added below line to Info.plist file

<key>FirebaseAppDelegateProxyEnabled</key><false/>

and added firebase configuration in appdelegate.swift file and notification started working.

import UIKit
import Flutter
import FirebaseCore
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, MessagingDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
     Messaging.messaging().delegate = self
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                    options: authOptions,
                    completionHandler: {_, _ in })
        }
        application.registerForRemoteNotifications()
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
Despoil answered 11/10, 2022 at 6:36 Comment(1)
Thanks a lot, i was trying to find where is the problem in my AppDelegate and just found your code is corrected my code exactly!Kalfas
P
-1

If you are testing on ios 10 plush device then try by adding below lines to your AppDelegate.swift file below FirebaseApp.configure()

 if #available(iOS 10.0, *) {
  UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
Pernik answered 5/3, 2020 at 10:1 Comment(1)
This is actually an error of firebase_messaging documentation, as mentioned here : github.com/FirebaseExtended/flutterfire/issues/… and other github issuesChristner

© 2022 - 2024 — McMap. All rights reserved.