TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

NotificationTapped not working #109

Closed elprofesor0710 closed 1 year ago

elprofesor0710 commented 1 year ago

Hi,

Can you please give us an example of NotificationTapped/NotificationReceived, navigating to other page? I tried something like this but it doen't work both android and iOS. Really appreciate any help thanks in advance.

`public App() { CrossFirebaseCloudMessaging.Current.NotificationReceived += NotificationReceived; CrossFirebaseCloudMessaging.Current.NotificationTapped += NotificationTapped; }

void NotificationReceived(object source, FCMNotificationReceivedEventArgs e) { //use e.Notification.Data await Shell.Current.GoToAsync($"//{nameof(Home)}", true); }

void NotificationTapped(object source, FCMNotificationTappedEventArgs e) { //use e.Notification.Data await Shell.Current.GoToAsync($"//{nameof(Home)}", true); } `

angelru commented 1 year ago

Hi,

Can you please give us an example of NotificationTapped/NotificationReceived, navigating to other page? I tried something like this but it doen't work both android and iOS. Really appreciate any help thanks in advance.

`public App() { CrossFirebaseCloudMessaging.Current.NotificationReceived += NotificationReceived; CrossFirebaseCloudMessaging.Current.NotificationTapped += NotificationTapped; }

void NotificationReceived(object source, FCMNotificationReceivedEventArgs e) { //use e.Notification.Data await Shell.Current.GoToAsync($"//{nameof(Home)}", true); }

void NotificationTapped(object source, FCMNotificationTappedEventArgs e) { //use e.Notification.Data await Shell.Current.GoToAsync($"//{nameof(Home)}", true); } `

what if you test Shell.Current.GoToAsync inside MainThread?

elprofesor0710 commented 1 year ago

I doesn't work either, even if you just put Console.WriteLine to get e.Notification.Data it doesn't trigger.

TobiasBuchholz commented 1 year ago

Try to call CrossFirebaseCloudMessaging.Current.NotificationTapped += NotificationTapped in your MainPage's ViewModel instead of the App constructor.

elprofesor0710 commented 1 year ago

@TobiasBuchholz thanks for your respose,CrossFirebaseCloudMessaging.Current.NotificationTapped += NotificationTapped works on android under App.cs but not on iOS, also when I tapped the push notification (iOS) the app crashes.

elprofesor0710 commented 1 year ago

@TobiasBuchholz I also think that it should be included on the documentation, some developers will need the NotificationTapped event.

elprofesor0710 commented 1 year ago

I can now confirm that it works for both android and iOS, just make sure in iOS AppDelegate.cs that there are no other method or event. also make sure that you delete the obj and bin files when you need to build/release the app.

this will work:

public App()
{
CrossFirebaseCloudMessaging.Current.NotificationReceived += NotificationReceived;
CrossFirebaseCloudMessaging.Current.NotificationTapped += NotificationTapped;
}

void NotificationReceived(object source, FCMNotificationReceivedEventArgs e)
{
//use e.Notification.Data
await Shell.Current.GoToAsync($"//{nameof(Home)}", true);
}

void NotificationTapped(object source, FCMNotificationTappedEventArgs e)
{
//use e.Notification.Data
await Shell.Current.GoToAsync($"//{nameof(Home)}", true);
}

What I suggest is to add this on the documentation, other developers might need it.