CrossGeeks / FirebasePushNotificationPlugin

Firebase Push Notification Plugin for Xamarin iOS and Android
MIT License
396 stars 178 forks source link

CrossFirebasePushNotification.Current.OnNotificationReceived not firing in iOS. #331

Open nmssalman opened 4 years ago

nmssalman commented 4 years ago

🐛 Bug Report

Here is how my AppDelegate looks like

`using System; using System.Collections.Generic; using System.Linq;

using Foundation; using Plugin.FirebasePushNotification; using UIKit;

namespace onlinefirebase.iOS { // The UIApplicationDelegate for the application. This class is responsible for launching the // User Interface of the application, as well as listening (and optionally responding) to // application events from iOS. [Register("AppDelegate")] public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate { // // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init();

        LoadApplication(new App());
        FirebasePushNotificationManager.Initialize(options, true);
        return base.FinishedLaunching(app, options);
    }
    public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {
        FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
    }

    public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {
        FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);

    }
    // To receive notifications in foregroung on iOS 9 and below.
    // To receive notifications in background in any iOS version
    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired 'till the user taps on the notification launching the application.

        // If you disable method swizzling, you'll need to call this method. 
        // This lets FCM track message delivery and analytics, which is performed
        // automatically with method swizzling enabled.
        FirebasePushNotificationManager.DidReceiveMessage(userInfo);
        // Do your magic to handle the notification data
        System.Console.WriteLine(userInfo);

        completionHandler(UIBackgroundFetchResult.NewData);
    }
}

} `

Here is how i receive notification.

`using System; using Plugin.FirebasePushNotification; using Xamarin.Forms; using Xamarin.Forms.Xaml;

namespace onlinefirebase { public partial class App : Application { public App() { InitializeComponent();

        MainPage = new MainPage();

        CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
        {
            System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}");
        };

        CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
        {
            System.Diagnostics.Debug.WriteLine("Received");
        };

    }

    protected override void OnStart()
    {
    }

    protected override void OnSleep()
    {
    }

    protected override void OnResume()
    {
    }
}

} `

I'm receiving Token successfully, but when i push the data from firebase console, i'm not receiving any data.

Can anyone advice me what's wrong with me iOS C# application? even in a new solution also the same. Version: 1.x

Platform:

almirvuk commented 4 years ago

@nmssalman please fix the code formatting on this issue, it is hard to follow it.

almirvuk commented 4 years ago

@rdelrosario maybe this is the same issue: 321.

daeyeonjoo commented 4 years ago

@almirvuk Hello~ I have same problem here. I got an message below from console in Xcode.

6.22.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

It is raised when I sent an message in Firebase Console.

frungillo commented 2 years ago

@daeyeonjoo same issue, have u resolved?

Dipannita20 commented 2 years ago

Same issue here, has anyone resolved? Thanks.

iOS version: 15.3 XCode: 13.2.1