Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use this library together with Xamarin.Firebase.Messaging? #58

Closed
suariana opened this issue Nov 30, 2024 · 11 comments
Closed

Can I use this library together with Xamarin.Firebase.Messaging? #58

suariana opened this issue Nov 30, 2024 · 11 comments

Comments

@suariana
Copy link

I have problem when building my project when i use Adame.Firebas.IOS.CloudMessaging
i've followed step of longpath issues but i still cannot build my project
i use Xamarin.Firebase.Messaging for android and Adame.Firebas.IOS.CloudMessaging for iOS
can both of library work together in the same project?
thank you

@AdamEssenmacher
Copy link
Owner

No. AdamE.iOS.Firebase.Core is incompatible with Xamarin.iOS.Firebase.Core, and also with any other package that includes common Firebase/Google iOS dependencies such as GTMSessionFetcher. This is documented in the project readme.

@AdamEssenmacher AdamEssenmacher closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2024
@suariana
Copy link
Author

suariana commented Dec 2, 2024

image
image
image
may i know which one of that package is not compatible with Plugin.Firebase?
because i still cannot build my project, there's no error long path or anything on error list
build process is stuck right there
image

it's run great when i deploy the project to android device, but the problem is when i deploy the project to ios device

image

i already removed old xamarin firebase messaging packages

image

im sorry, is this the right place to ask about this?
because i'm using nuget packages Plugin.Firebase now, then i see same problem on the link below
TobiasBuchholz/Plugin.Firebase#325

thank you

@maonaoda
Copy link

maonaoda commented Dec 2, 2024

@AdamEssenmacher
Does this mean that it cannot be used together with Xamarin.Google.iOS.SignIn?

@AdamEssenmacher
Copy link
Owner

@suariana I think I misunderstood your first question, so let me try again.

The nugets published from this repository are binding libraries for native iOS SDKs--they have nothing to do with Android. They only make sense in the context of iOS. They shouldn't be included in any builds that target any other platform. If you're referencing these packages directly in a multi-target project (e.g. MAUI), then the packages should be conditionally included (see the readme).

Based on your screenshot, the build is hanging while XamarinBuildDownload is trying to extract GAppM. Check the project readme for troubleshooting steps around Windows and 7Zip.

@AdamEssenmacher
Copy link
Owner

@maonaoda Mixing Xamarin.Google.iOS.SignIn with any AdamE.Firebase.iOS.* NuGet package is not recommended. This is because Xamarin.Google.iOS.SignIn depends on Xamarin.Firebase.iOS.Core, while AdamE.Firebase.iOS.Core is a replacement for Xamarin.Firebase.iOS.Core. Using both in the same project will cause both to link to the same set of native libraries (e.g., GTMSessionFetcher and PromisesObjC) but with different versions. This could lead to build-time issues or, worse, runtime conflicts. For more details about these incompatibilities, please refer to the project README.

If you're interested in adding Google Sign-In support to this project, I'd gladly review a community PR. Google Sign-In would likely follow a similar implementation to Google Maps, which was recently added. Reviewing the commit history for that feature could serve as a helpful guide.

Alternatively, if you'd like to see this feature prioritized, I offer one-time sponsorship options on my GitHub profile that could cover an afternoon of my time.

@maonaoda
Copy link

maonaoda commented Dec 3, 2024

Based on your screenshot, the build is hanging while XamarinBuildDownload is trying to extract GAppM. Check the project readme for troubleshooting steps around Windows and 7Zip.
same with
dotnet/android-libraries#1047

@maonaoda
Copy link

maonaoda commented Dec 3, 2024

@maonaoda Mixing Xamarin.Google.iOS.SignIn with any AdamE.Firebase.iOS.* NuGet package is not recommended. This is because Xamarin.Google.iOS.SignIn depends on Xamarin.Firebase.iOS.Core, while AdamE.Firebase.iOS.Core is a replacement for Xamarin.Firebase.iOS.Core. Using both in the same project will cause both to link to the same set of native libraries (e.g., GTMSessionFetcher and PromisesObjC) but with different versions. This could lead to build-time issues or, worse, runtime conflicts. For more details about these incompatibilities, please refer to the project README.

If you're interested in adding Google Sign-In support to this project, I'd gladly review a community PR. Google Sign-In would likely follow a similar implementation to Google Maps, which was recently added. Reviewing the commit history for that feature could serve as a helpful guide.

Alternatively, if you'd like to see this feature prioritized, I offer one-time sponsorship options on my GitHub profile that could cover an afternoon of my time.

Thank you for your detailed explanation,
I was able to get the build to work by replacing the GoogleAppMeasurement files,
but do have some concerns about the runtime issue (may be)

@suariana
Copy link
Author

suariana commented Dec 3, 2024

@suariana I think I misunderstood your first question, so let me try again.

The nugets published from this repository are binding libraries for native iOS SDKs--they have nothing to do with Android. They only make sense in the context of iOS. They shouldn't be included in any builds that target any other platform. If you're referencing these packages directly in a multi-target project (e.g. MAUI), then the packages should be conditionally included (see the readme).

Based on your screenshot, the build is hanging while XamarinBuildDownload is trying to extract GAppM. Check the project readme for troubleshooting steps around Windows and 7Zip.

Thank you, my project can be built now
but, is this library compatible with dotnet 8?
because i cannot receive notification on ios?
i only using adame firebase cloud messaging for my project to replace old Xamarin.Firebase.IOS.CloudMessaging

image
image

I've added this too
image

i cannot receive any notification on debug or release build
im using iphone 6s, ios 15.7.1
thank you

@AdamEssenmacher
Copy link
Owner

It's important to recognize that the AdamE version of FCM advances the underlying native SDK version two major versions (from 8.10 to 10.16+). Native configuration requirements changed.

I'm guessing your problem stems from config changes related to method swizzling.

Yes, these bindings work on .net 6 through 9.

@suariana
Copy link
Author

suariana commented Dec 3, 2024

using Firebase.CloudMessaging;
using Foundation;
using UIKit;
using UserNotifications;

namespace FirebaseNotification.Platforms.iOS
{

public class FirebaseService : NSObject, IMessagingDelegate
{

    internal static void Initialize()
    {

        var fs = new FirebaseService();
        fs.Configure();

    }

    private void Configure()
    {
        Firebase.Core.App.Configure();
        if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
        {
            var authOption = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;

            UNUserNotificationCenter.Current.RequestAuthorization(authOption, (granted, error) =>
            {
                Console.WriteLine($"Registration is success: {granted}");

                if (error != null)
                {
                    Console.WriteLine($"Registration for push notifications error: {error.DebugDescription}");
                }

                if (granted && error == null)
                {
                    this.InvokeOnMainThread(() =>
                    {
                        UIApplication.SharedApplication.RegisterForRemoteNotifications();
                        this.RegisterNotification();
                    });
                }
            });


        }


    }

    private void RegisterNotification()
    {
        UNUserNotificationCenter.Current.Delegate = new Platforms.iOS.UserNotificationCenterDelegate();
        Messaging.SharedInstance.AutoInitEnabled = true;
        Messaging.SharedInstance.Delegate = this;
        GetToken();
    }

    private void GetToken()
    {
        var token = Messaging.SharedInstance.FcmToken;
        FirebaseNotification.Current.InvokeTokenRefresh(token);
    }

    internal static void SubscribeToTopic(string topic)
    {
        Messaging.SharedInstance.Subscribe(topic);
    }

    internal static void UnsubscribeTopic(string topic)
    {
        Messaging.SharedInstance.Unsubscribe(topic);
    }

    [Export("messaging:didReceiveRegistrationToken:")]
    private void DidReceiveRegistrationToken(Messaging message, string regToken)
    {
        FirebaseNotification.Current.InvokeTokenRefresh(regToken);
    }


}

}

using Foundation;
using UserNotifications;

namespace FirebaseNotification.Platforms.iOS
{
public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
{

    public static UNNotificationPresentationOptions CurrentNotificationPresentationOption { get; set; } = UNNotificationPresentationOptions.None;

    public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
    {
        var userInfo = response.Notification.Request.Content.UserInfo;
        var parameters = GetParameters(userInfo);
        Current.InvokeNotificationOpened(parameters);
        completionHandler();
    }

    public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
    {
        var userInfo = notification.Request.Content.UserInfo;

        var parameters = GetParameters(userInfo);
        Current.InvokeNotificationReceived(parameters);

        //Tambil notif terus
        //completionHandler(UNNotificationPresentationOptions.Alert);

        // Tampil notif hanya yang penting
        if ((parameters.TryGetValue("priority", out var priority) && ($"{priority}".ToLower() == "high" || $"{priority}".ToLower() == "max")))
        {
            if (!CurrentNotificationPresentationOption.HasFlag(UNNotificationPresentationOptions.Alert))
            {
                CurrentNotificationPresentationOption |= UNNotificationPresentationOptions.Alert;

            }
        }
        else if ($"{priority}".ToLower() == "default" || $"{priority}".ToLower() == "low" || $"{priority}".ToLower() == "min")
        {
            if (CurrentNotificationPresentationOption.HasFlag(UNNotificationPresentationOptions.Alert))
            {
                CurrentNotificationPresentationOption &= ~UNNotificationPresentationOptions.Alert;

            }
        }
        completionHandler(CurrentNotificationPresentationOption);
    }


    private static IDictionary<string, string> GetParameters(NSDictionary data)
    {
        var parameters = new Dictionary<string, string>();

        var keyAps = new NSString("aps");
        var keyAlert = new NSString("alert");

        foreach (var val in data)
        {
            if (val.Key.Equals(keyAps))
            {
                var aps = data.ValueForKey(keyAps) as NSDictionary;

                if (aps != null)
                {
                    foreach (var apsVal in aps)
                    {
                        if (apsVal.Value is NSDictionary)
                        {
                            if (apsVal.Key.Equals(keyAlert))
                            {
                                foreach (var alertVal in apsVal.Value as NSDictionary)
                                {
                                    parameters.Add($"aps.alert.{alertVal.Key}", $"{alertVal.Value}");
                                }
                            }
                        }
                        else
                        {
                            parameters.Add($"aps.{apsVal.Key}", $"{apsVal.Value}");
                        }

                    }
                }
            }
            else
            {
                parameters.Add($"{val.Key}", $"{val.Value}");
            }

        }


        return parameters;
    }

}

}

im sorry may i know that im using method swizzling or not?
im not set this flag FirebaseAppDelegateProxyEnabled on info.plist

@AdamEssenmacher
Copy link
Owner

Closing this now because the original issue has been solved and the conversation is starting to sprawl.

@suariana the FCM bindings work. If you're not getting notifications, it is almost certainly because your project is just misconfigured somehow. There are a few issues discussing the same sort of problem over at Plugin.Firebase that might push you in the right direction:

TobiasBuchholz/Plugin.Firebase#324
TobiasBuchholz/Plugin.Firebase#192
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants