Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Push notification not displaying on IOS

Tags:

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

like image 527
Billy Mahmood Avatar asked Oct 09 '19 08:10

Billy Mahmood


People also ask

How do I run a flutter app in iOS physical device?

To test or deploy our flutter app to a physical device we first need to enable physical device deployment in Xcode using Apple ID or an Apple Developer account. And we also need to set up a package manager to manage flutter plugins that are to be used in the project.

How do I run a flutter code on iOS?

You need to go to your Settings > General > Device Management. Inside Device Management, select the developer name and tap Trust “YOUR DEVELOPER NAME”. You should now be able to run your Flutter app on your local device.

Can we make iOS app using flutter?

Flutter is a multi-platform application development framework that enables you, among other platforms, to develop iOS and Android apps from the same source code. However, you need to use Xcode to build an iOS app and Xcode will only work on macOS. You cannot get away with Linux or Windows.


1 Answers

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?

  • https://github.com/FirebaseExtended/flutterfire/issues/1799
    • Only shows in foreground, RE: 5) I have closed the app / sent it to the background when testing - still no luck
  • https://github.com/FirebaseExtended/flutterfire/issues/1590
    • related to the background issue
  • https://github.com/FirebaseExtended/flutterfire/issues/1797
    • did you try from the console?, RE: Stefano Saitta's comment
  • https://github.com/FirebaseExtended/flutterfire/issues/1677
    • works on Android, but not iOS
  • https://github.com/FirebaseExtended/flutterfire/issues/1581
    • other plugins can break it?

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

like image 163
TWL Avatar answered Sep 18 '22 14:09

TWL