TobiasBuchholz / Plugin.Firebase

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

iOS foreground notification is not showing up #194

Open advance-through-prac opened 11 months ago

advance-through-prac commented 11 months ago

Hi not sure if this is the right place to post..

I couldn't receive notification when the (iOS) app is in foreground, not sure what is the cause of it. no issue receiving notification when its in background. Tested it on my iOS device.

any idea if I am missing anything? or should I override willpresentnotification in appdelegate?

been searching around but couldn't find a solution to it.

in MauiProgram.cs:

image

in appdelegate:

image
TobiasBuchholz commented 11 months ago

Hi, did you start the application without the debugger attached?

Otherwise how are you sending the notification? Did you try to use the curl command of the documentation:

curl --location 'https://fcm.googleapis.com/fcm/send' \
--header 'Authorization: key=<your-api-token-from-firebase-console-cloud-messaging-project-settings>' \
--header 'Content-Type: application/json' \
--data '{
 "to" : "<your-device-fcm-token>",
 "collapse_key" : "type_a",
 "mutable_content": true,
 "notification" : {
     "title": "Knock knock",
     "body" : "Who's there?",
     "badge": 1
 },
 "data" : {
     "body" : "body of your notification in data",
     "title": "title of your notification in data",
     "is_silent_in_foreground": false
 }
}'
advance-through-prac commented 11 months ago

Hi yup. started the app without debugging.

im sending notification through the firebase console

image

and firebaseadmin from server

image

will try curl command

EdwardMcFlurry commented 11 months ago

Hi not sure if this is the right place to post..

I couldn't receive notification when the (iOS) app is in foreground, not sure what is the cause of it. no issue receiving notification when its in background. Tested it on my iOS device.

any idea if I am missing anything? or should I override willpresentnotification in appdelegate?

been searching around but couldn't find a solution to it.

in MauiProgram.cs: image

in appdelegate: image

@advance-through-prac did you say that you can receive the Notification Ps when running physically on iPhone while on foreground and not background?

I can’t seem to receive any whether running on foreground or background on my iPhone in Production but everything works well on Android.

Gekidoku commented 10 months ago

I found that sometimes the lifecycle event FinishedLaunching acts up on ios. Instead I found that WillFinishLaunching worked better / more consistenly.

events.AddiOS(iOS => iOS.WillFinishLaunching((_, options) =>
{
CrossFirebase.Initialize(CreateCrossFirebaseSettings());
return false;
}));
Drol commented 10 months ago

I found that sometimes the lifecycle event FinishedLaunching acts up on ios. Instead I found that WillFinishLaunching worked better / more consistenly.

events.AddiOS(iOS => iOS.WillFinishLaunching((_, options) =>
{
CrossFirebase.Initialize(CreateCrossFirebaseSettings());
return false;
}));

Sorry for hijacking but I can't get any notifications to work on ios but it works perfectly fine on Android. Is CreateCrossFirebaseSettings needed? I fined it very confusing because some documentation have it and some have it like the code below.

          events.AddiOS(ios => ios.FinishedLaunching((_, __) =>
          {
              CrossFirebase.Initialize();
              FirebaseCloudMessagingImplementation.Initialize();
              return false;
          }));
TobiasBuchholz commented 10 months ago

@Drol It depends on whether you are using the bundled version of the plugin or just the single feature version. If you are using Plugin.Firebase the CrossFirebaseSettings are needed, if you are using Plugin.Firebase.CloudMessaging they are not.

Drol commented 10 months ago

@Drol It depends on whether you are using the bundled version of the plugin or just the single feature version. If you are using Plugin.Firebase the CrossFirebaseSettings are needed, if you are using Plugin.Firebase.CloudMessaging they are not.

Oh thanks I didnt realize that. Maybe that explains why it wont work for me on Ios :-)

Edit: It did not help. So I have to remove the package Plugin.Firebase and only install Plugin.Firebase.CloudMessaging? But I am using Plugin.Firebase.Firestore and Plugin.Firebase.Storage aswell and those are working fine. So I should install all those?

Edit2: Nevermind I got it working.

Paulpetta668 commented 10 months ago

Hi, how did you resolve it at the end? i followed the conversation but i cant get it working on iOS. (Android working just fine)

aelmardi commented 9 months ago

Hello, same thing on my side it works perfectly on Android but on iOS nothing to do. I followed the tutorial to the letter.

omxie commented 8 months ago

EDIT: I take that back, not working for me yet!

Thanks @Gekidoku, after using WillFinishLaunching, everything is working fine for me now! I'm using dotnet 7 with Plugin.Firebase.CloudMessaging

hongyangsong commented 6 months ago

Do the following in AppDelegate class. image