TobiasBuchholz / Plugin.Firebase

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

Is DotNet 7 MAUI supported? #200

Closed SteveSitekitcare closed 9 months ago

SteveSitekitcare commented 11 months ago

Hi

I have a basic example of a MAUI app built on dot net 7. The target is only android. I added the google-services.json (not in the source due to security)

I also added the analytics package and configured. I dont see anything in firebase even though the app works?

Code sample is here (just add a google-services.json file) https://github.com/SteveSitekitcare/Plugin.Firebase.net7.0

Cheers

My setup is

Windows 10 Pro Microsoft Visual Studio Community 2022 Version 17.7.4 VisualStudio.17.Release/17.7.4+34031.279 Microsoft .NET Framework Version 4.8.09037

Installed Version: Community

ASP.NET and Web Tools 17.7.273.65229 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.7.273.65229 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.7.273.65229 Azure Functions and Web Jobs Tools

C# Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.4.34 (main@d5ab18b) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.7.27 (547ea6f) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.7.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.7.10.1 Microsoft SQL Server Data Tools

TypeScript Tools 17.0.20829.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.7.0.216 (d17-7@133ddef) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.7.3.9 (remotes/origin/d17-7@796d191def) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.1.2 (d17-5/a8a26c7) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Paulpetta668 commented 11 months ago

I can say that it works for NET7.0, im currently using it; the app works as it runs or as it receives notification? I looked at your code and you are missing the configuration in the Android part (Android manifest and Mainactivity.cs)

SteveSitekitcare commented 11 months ago

I can say that it works for NET7.0, im currently using it; the app works as it runs or as it receives notification? I looked at your code and you are missing the configuration in the Android part (Android manifest and Mainactivity.cs)

Hi

I dont see any instructions for the manifest? The mainactivity.cs is only mentioned when using the emulator?

Can you emphasise on what exactly I'm missing?

Paulpetta668 commented 11 months ago

Im referring to this for the android manifest. Then u need to create the channel, this i done in the mainactivity.

My MainActivity.cs

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    HandleIntent(Intent);
    CreateNotificationChannelIfNeeded();
}

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    HandleIntent(intent);
}

private static void HandleIntent(Intent intent)
{
    FirebaseCloudMessagingImplementation.OnNewIntent(intent);
}

private void CreateNotificationChannelIfNeeded()
{
    if(Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
    {
        if(ContextCompat.CheckSelfPermission(this, Manifest.Permission.PostNotifications) != Permission.Granted)
        {
            ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.PostNotifications }, 0);
        }
    }

    if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
    {
        CreateNotificationChannel();
    }
}

private void CreateNotificationChannel()
{
    var channelId = $"{PackageName}.general";
    var notificationManager = (NotificationManager)GetSystemService(NotificationService);
    var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
    notificationManager.CreateNotificationChannel(channel);
    FirebaseCloudMessagingImplementation.ChannelId = channelId;
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
SteveSitekitcare commented 11 months ago

Im referring to this for the android manifest. Then u need to create the channel, this i done in the mainactivity.

My MainActivity.cs

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    HandleIntent(Intent);
    CreateNotificationChannelIfNeeded();
}

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    HandleIntent(intent);
}

private static void HandleIntent(Intent intent)
{
    FirebaseCloudMessagingImplementation.OnNewIntent(intent);
}

private void CreateNotificationChannelIfNeeded()
{
    if(Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
    {
        if(ContextCompat.CheckSelfPermission(this, Manifest.Permission.PostNotifications) != Permission.Granted)
        {
            ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.PostNotifications }, 0);
        }
    }

    if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
    {
        CreateNotificationChannel();
    }
}

private void CreateNotificationChannel()
{
    var channelId = $"{PackageName}.general";
    var notificationManager = (NotificationManager)GetSystemService(NotificationService);
    var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
    notificationManager.CreateNotificationChannel(channel);
    FirebaseCloudMessagingImplementation.ChannelId = channelId;
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

This looks likes its for the messaging side of firebase, Im using analytics and crashlytics? I dont use messaging

Paulpetta668 commented 11 months ago

Oh, my bad, i know for sure that this plugin work for NET7.0, i dont know for analytics and crashalytics, sry if i wasted your time

shaboboo commented 11 months ago

I'm also struggling greatly to get this working in .net 7 Trying to figure our which nuget packages are required to get the code samples working, as the ones in the examples I see for .net 6 are not playing well together and causing additional issues.

Would love to see the example code here updated to .net 7 https://github.com/TobiasBuchholz/Plugin.Firebase/blob/development/sample/Playground/MauiProgram.cs

criss02-cs commented 11 months ago

Hi, I'm trying to use Firebase authentication with .net7 but when I try to create a user it keeps blocking me, here I leave you the link to my project: https://github.com/criss02-cs/ToDoListMaui When I try to register the user I get the line var user = await Auth.CreateUserAsync(Email, Password); and it gets stuck there and never comes out

ClausElmann commented 11 months ago

I can say that it works for NET7.0, im currently using it; the app works as it runs or as it receives notification? I looked at your code and you are missing the configuration in the Android part (Android manifest and Mainactivity.cs)

I can say that it works for NET7.0, im currently using it; the app works as it runs or as it receives notification? I looked at your code and you are missing the configuration in the Android part (Android manifest and Mainactivity.cs)

@Paulpetta668 could you post a simple sample that works - somewhere :-)

ahoymehearties commented 10 months ago

Adding to the chorus of "how the eff do we do this in .NET 7." :) Microsoft recommends binding directly to libraries and links to a 44 minute video of a guy with a super thick accent doing a powerpoint, which is not great.

ahoymehearties commented 10 months ago

For those in the peanut gallery, I was able to achieve this very easily with OneSignal as a firebase intermediary.

Check the .NET MAUI docs here

SteveSitekitcare commented 10 months ago

For those in the peanut gallery, I was able to achieve this very easily with OneSignal as a firebase intermediary.

Check the .NET MAUI docs here

Those instructions do not make any sense for me. After speaking to there support team, they dont actually support maui yet.

I got the app running but it has exactly the same issue as plugin.firebase, the implemenation was null

TobiasBuchholz commented 9 months ago

Maui with .net7 is definetly supported, the sample and test projects are using it now as well as the dedicated demo project of @andyzukunft.

shaboboo commented 9 months ago

I am unable to get the playground sample code (from master branch) to compile.

In Playground.MauiProgram.cs neither CrossFirebase.Initialize or FirebaseAuthGoogleImplementation.Initialize can be found.

image

I will try the dedicated demo next

Edit: Wasn't able to get the demo to fully compile either, but the MauiProgram.cs IS able to call the initialize function at least. I feel safe enough to make another attempt to this working in my own solution

Edit 2: In both my project and the dedicated demo project above, I am hitting exception trying to get device token await CrossFirebaseCloudMessaging.Current.GetTokenAsync();

Message: "Default FirebaseApp is not initialized in this process pbsconnect.sales.droid. Make sure to call FirebaseApp.initializeApp(Context) first."

This is the same issue I was hitting before, not sure how to resolve.