Azure / AzureNotificationHubs

Azure Notification Hubs
MIT License
2 stars 5 forks source link

Migration for Xamarin? #5

Open Viraj-KP opened 4 years ago

Viraj-KP commented 4 years ago

AppCenter Push was super friendly for Xamarin Forms projects, is there a migration guide for that?

james1301 commented 4 years ago

Yes we need a migration guide for Xamarin Forms.

merzink commented 4 years ago

Quick update: The product team will look into this request. Thanks for your feedback! Just for awareness, Xamarin bindings for our recently released preview SDKs are published - native Android is available here (and iOS update coming shortly).

GiampaoloGabba commented 4 years ago

we will have a xamarin.forms/.net Maui specific SDK like AppCenter had, or we need to write tons of platforms specific code?

developer9969 commented 4 years ago

In order to make it easier we need a good working sample implementation using Xamarin Forms. We would like to realistically see how much platform specific code we need to write, Ideally a walk through that guides from beginning to end.

almirvuk commented 4 years ago

Not sure why Xamarin/Xamarin.Forms SDK is not available yet or sooner. A lot of users are forced to move to Firebase or some other services similar to App Center due to not having the real and updated SDK solution for this migration problem.

This Push feature was a great solution and you decided to move to Azure Notification Hub and still, we don't have an SDK after more than 4 months to follow this migration.

The first deadline for that was sometimes in summer and now is moved to the end of the year... time is ticking and the real question is when we will have the stable solution to follow all the migrations and transition for the current user base.

Xamarin devs did not get the same amount of attention. 😞

ehuna commented 4 years ago

Quick update: The product team will look into this request. Thanks for your feedback! Just for awareness, Xamarin bindings for our recently released preview SDKs are published - native Android is available here (and iOS update coming shortly).

I see there's a sample project here: https://github.com/xamarin/XamarinComponents/tree/master/XPlat/AzureMessaging/Android/samples

I tried using it with the "1.0.0-preview2" nuget package from here: https://www.nuget.org/packages/Xamarin.Azure.NotificationHubs.Android/1.0.0-preview2

I created my azure notifications hub in the portal and I set my CONNECTION_STRING and HUB_NAME accordingly, but when I run, in the following line -

NotificationHub.Initialize(Application, HUB_NAME, CONNECTION_STRING);

I get -

Java.Lang.IllegalArgumentException Message=Endpoint parameter can not be null or empty

After I added "Endpoint=" to the "DefaultListenSharedAccessSignature" connection string I retrieved from the azure portal, I now get -

Java.Lang.RuntimeException: 'Unable to create service com.microsoft.windowsazure.messaging.notificationhubs.FirebaseReceiver: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.azuremessaging.sample. Make sure to call FirebaseApp.initializeApp(Context) first.'

If you expect us to migrate, we really need better documentation and samples for Xamarin Forms developers. :(

tjsomasundaram-zz commented 4 years ago

Thank you for the ask. We hear your request and the team is working on a Xamarin Forms sample that we should be able to publish soon. I will take this error back to the engineering team to troubleshoot.

Viraj-KP commented 4 years ago

Any update on this? @tjsomasundaram

tjsomasundaram-zz commented 4 years ago

Hi Viraj-KP, here are the Xamarin Forms samples : https://github.com/Azure/azure-notificationhubs-xamarin

Dfergy commented 4 years ago

I downloaded the Xamarin Forms sample, when running the Android project I get the same FirebaseApp is not initialized error as noted above. Any updates on this?

marstr commented 4 years ago

Howdy @Viraj-KP, @ehuna, and @Dfergy. Sorry you're running into trouble! There are a few details that can get in the way of Firebase initializing. Largely, it means that for some reason Android wasn't able to validate your application for use with a specific Firebase Cloud Messaging project.

We do totally hear your feedback. We want to make sure that the migration documentation is not a painful experience. For the problem you're encountering specifically, run through this list of potential problems:

Regardless of whether you're using Xamarin or Java, the first things to check are:

If your app is written in C# with Xamarin

If your app is written in Kotlin/Java and uses Gradle

If it's any consolation, in writing this up and making sure that it works for me, I had to download a new copy of my google-services.json. I had cluttered up my Firebase project during development, and decided to get a fresh start by deleting all of the applications associated with my project. I of course promptly forgot about that and ran into the same error that you're seeing just now. Once I updated google-services, everything started working as expected.

Dfergy commented 4 years ago

Thanks

You were right, once I double checked everything was correct with my google-servcies.json and it had the proper build action, the code will run and not exception out. Since then, what I’ve tried is to upload a test app to App Center, built and downloaded the APK and installed on my phone, and tried to send a notification to my phone from my Notification Hub. (already created)

On the Notification Hub, it shows success, see below, but no sign of a notification on my phone.

Is anything else needed to get the sample code to work end to end like this?

Thanks

[cid:image003.jpg@01D66A7F.BB086A10]

From: Martin Strobel notifications@github.com Sent: Friday, July 24, 2020 4:32 PM To: Azure/AzureNotificationHubs AzureNotificationHubs@noreply.github.com Cc: Dave Ferguson DFerguson@usbnc.org; Mention mention@noreply.github.com Subject: Re: [Azure/AzureNotificationHubs] Migration for Xamarin? (#5)

Howdy @Viraj-KPhttps://github.com/Viraj-KP, @ehunahttps://github.com/ehuna, and @Dfergyhttps://github.com/Dfergy. Sorry you're running into trouble! There are a few details that can get in the way of Firebase initializing. Largely, it means that for some reason Android wasn't able to validate your application for use with a specific Firebase Cloud Messaging project.

We do totally hear your feedback. We want to make sure that the migration documentation is not a painful experience. For the problem you're encountering specifically, run through this list of potential problems:

Regardless of whether you're using Xamarin or Java, the first things to check are:

Xamarin Specific

· [ ] Is google-services.json in your project's Properties? [image]https://user-images.githubusercontent.com/11203166/88435455-11d36f80-cdb7-11ea-844e-5debd890d188.png

· [ ] Is google-services.json set to have the Build Action of GoogleServicesJson? [image]https://user-images.githubusercontent.com/11203166/88435537-3fb8b400-cdb7-11ea-916d-1443e96c35fe.png

Java/Kotlin Specific

If it's any consolation, in writing this up and making sure that it works for me, I had to download a new copy of my google-services.json. I had cluttered up my Firebase project during development, and decided to get a fresh start by deleting all of the applications associated with my project. I of course promptly forgot about that and ran into the same error that you're seeing just now. Once I updated google-services, everything started working as expected.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Azure/AzureNotificationHubs/issues/5#issuecomment-663742890, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL3NAO3OGJEG7GU5RPTQ2JTR5H4VTANCNFSM4M44GDSA.

marstr commented 4 years ago

Glad to hear you're making progess, @Dfergy. Couple of things:

  1. The Notification Hub SDK will alert a callback in your code when a notification has been received. It doesn't actually render that notification for you, so depending on how you're using your phone you may not see a visible notification. Check for logs, and/or attach a debugger to see if your callback is being invoked. If you would like to visualize all notifications that go to the phone, you can checkout this documentation. We're definitely open to feedback here, feel free to open new issues.
  2. The state of your app is pretty crucial to how Android/Firebase will deliver notifications it receives. There are also two different families of payload sent to the device: data messages, and notifications. You can read more about when Android delivers it here. Depending on the message you've been sending and the state of your app, that could be interfering with things as well.
Dfergy commented 4 years ago

Thanks

After reviewing I realized that the default test message in the Notification Hub is a data message. Once I changed it to a notification, I got the notification on my phone, but only while the app was running or in the background. I get the same results using Firebase console directly. We were used to having the App Center Push notifications appear in the system notification list whether the app was running or not. Once we had our google-services.json in place and started App Center Push on startup, we got this behavior out of the box without any additional coding or configuration.

I’ve been reading the documentation but can’t quite discern yet how to get this to happen. Any pointers in the right direction would be appreciated.

From: Martin Strobel notifications@github.com Sent: Tuesday, August 4, 2020 6:24 PM To: Azure/AzureNotificationHubs AzureNotificationHubs@noreply.github.com Cc: Dave Ferguson DFerguson@usbnc.org; Mention mention@noreply.github.com Subject: Re: [Azure/AzureNotificationHubs] Migration for Xamarin? (#5)

Glad to hear you're making progess, @Dfergyhttps://github.com/Dfergy. Couple of things:

  1. The Notification Hub SDK will alert a callback in your code when a notification has been received. It doesn't actually render that notification for you, so depending on how you're using your phone you may not see a visible notification. Check for logs, and/or attach a debugger to see if your callback is being invoked. If you would like to visualize all notifications that go to the phone, you can checkout this documentationhttps://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/. We're definitely open to feedback here, feel free to open new issues.
  2. The state of your app is pretty crucial to how Android/Firebase will deliver notifications it receives. There are also two different families of payload sent to the device: data messages, and notifications. You can read more about when Android delivers it herehttps://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages. Depending on the message you've been sending and the state of your app, that could be interfering with things as well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Azure/AzureNotificationHubs/issues/5#issuecomment-668876302, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL3NAO3V4BZPLNUDIGCT4UDR7CKCTANCNFSM4M44GDSA.

marstr commented 4 years ago

Thanks for sticking with it, @Dfergy. I should be clear that at least for the moment, we don't make the same attempt to show notifications that App Center Push did. You'll need to build a NotificationListener that you then register with the NotificatonHub global single instance. That NotificationListener's only job in life can be turn around and render the Notification with Xamarin or Android libraries.

We hear the feedback that this is harder than it was in App Center. If this is a common enough concern, we could try to provide a default NotificationListener implementation.

Dfergy commented 4 years ago

OK.

One more question, is this Microsoft.Azure.NotificationHubs.Client project you’re giving us going to become a full-fledged NuGet package, like the native projects, and if so, what is the ETA?

From: Martin Strobel notifications@github.com Sent: Wednesday, August 12, 2020 4:03 PM To: Azure/AzureNotificationHubs AzureNotificationHubs@noreply.github.com Cc: Dave Ferguson DFerguson@usbnc.org; Mention mention@noreply.github.com Subject: Re: [Azure/AzureNotificationHubs] Migration for Xamarin? (#5)

Thanks for sticking with it, @Dfergyhttps://github.com/Dfergy. I should be clear that at least for the moment, we don't make the same attempt to show notifications that App Center Push did. You'll need to build a NotificationListenerhttps://github.com/Azure/azure-notificationhubs-android/blob/5f8189f58e76191a9f0e20aa4bc57728e72d57eb/notification-hubs-sdk/src/main/java/com/microsoft/windowsazure/messaging/notificationhubs/NotificationListener.java#L5 that you set as the object that should be informed when a notification is received. That NotificationListener's only job in life can be turn around and render the Notification with Xamarinhttps://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/ or Androidhttps://developer.android.com/guide/topics/ui/notifiers/notifications libraries.

We hear the feedback that this is harder than it was in App Center. If this is a common enough concern, we could try to provide a default NotificationListener implementation.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Azure/AzureNotificationHubs/issues/5#issuecomment-673109166, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL3NAO6V4K66FKHED7SKVZLSAL7O7ANCNFSM4M44GDSA.

marstr commented 4 years ago

@Dfergy, I'm afraid I can't make promises around the Microsoft.Azure.NotificationHubs.Client package. I can say that we do recognize the customer pain that it would fix, and we would like to publish it or something like it.