Xcelerator-Group / dotnet-maui-notifications

An example of how to use Azure Notification Hub with .NET Maui
10 stars 2 forks source link

Default FirebaseApp is not initialized in this process com.kronos.not. Make sure to call FirebaseApp.initializeApp(Context) first. #1

Open mwnovaprove opened 12 months ago

mwnovaprove commented 12 months ago

Hi,

I get this error while trying to execute your project. Notice that I did exactly what you suggested in changing the Azure Notification Hub Connection String and Hub Name. I also changed the package_name of my google-services.json file. The exception is thrown at NotificationHub.Start(this.Application, HUB_NAME, CONNECTION_STRING); Here's the detail:

Java.Lang.IllegalStateException: 'Default FirebaseApp is not initialized in this process com.kronos.not. Make sure to call FirebaseApp.initializeApp(Context) first.'

Consider that I couldn't set the google-services.json as a GoogleService resource in its properties because I can't find the option (due to Xamarin.GooglePlay.Base not compliant with the various package references already installed).

What is your advice?

Thanks, W.

rob-baily commented 12 months ago

Hi! Did you have the error using this project as is or with some other project that tries to use some aspects of this?

Also I did not get what you mean about the google-services.json.

BTW we have changed to using Shiny (https://shinylib.net/) as it nicely handles this for both Android and iOS for using Notification Hubs.

mwnovaprove commented 12 months ago

Hi! I got the error with the project as is.

So you moved to Shiny, I heard about it and it seems nice. Do you have any sample I can use to go through the matter with Shiny?

rob-baily commented 12 months ago

I don't have a sample ready on Shiny right this moment. You can get some of the code using his app builder here https://shinylib.net/client/appbuilder/. I also leaned heavily on the samples at https://github.com/shinyorg/shiny/tree/master/samples to pull out what I needed. I may try to get a sample out in the next few days but I would suggest giving it a try yourself to start.

mwnovaprove commented 11 months ago

First of all thanks a lot for your availability 🙏🏽 I gave it a try myself and I was able to add the Azure Notification Hub service in the Program.cs of my project, add permission prompt and get the registration token from the service. The only thing is that I can’t register the token on Azure so that I can then receive the push notification. Do you have any idea on how to do it?

rob-baily commented 11 months ago

Not quite quite what you mean by both statements.

mwnovaprove commented 11 months ago

Yes, I was able to call “pushManager.RequestAccess” and get the token (after including the google-services.json file obtained in Firebase console). I tried to send a sample notification through Azure in the test section (without specifying the token within the payload, assuming it would send a broadcast notification with no user distinction) but I can’t receive it. So I thought that a specific registration on Azure was needed. From your reply, I understand I’m missing something in the picture 🙌🏽🥴

rob-baily commented 11 months ago

I take it you have hooked up Notification Hubs to the Google messaging service with the API key and sent a test to the Android platform?

For Android it looks like you also need this in your manifest: <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

mwnovaprove commented 11 months ago

Thanks a lot for coming back to me. Everything is working on Android even without the option you mentioned in the manifest. The Received() method is correctly called and then I am able to create a local notification and present it to the user (no matter if the app is background, foreground or closed). Talking about iOS, do you have any suggestion on how to implement the local notification once the payload has been received by the delegate? Do you have a unique method to manage the notification to the user (once it has been received) which is valid for both Android and iOS?

rob-baily commented 11 months ago

Sorry at this point I don't have anything for the local notification in general.

mwnovaprove commented 11 months ago

All right, so how do you pop out the notification to the user after having received it?