Closed sdworx-kennydv closed 7 months ago
@sdworx-kennydv Thanks for your feedback! We will investigate and update as appropriate.
@sdworx-kennydv I have assigned this to content author @sethmanheim to review and share his valuable insights on this.
From my own testing it does seem the PHN handle can be reused so the documentation in that view is correct, but maybe some extra clarification could be useful
code samples given here https://learn.microsoft.com/en-us/azure/notification-hubs/firebase-migration-sdk are confusing and unclear
i have included <PackageReference Include="Microsoft.Azure.NotificationHubs" Version="4.2.0" />
in my project
NotificationHub hub = new NotificationHub(BuildConfig.hubName, BuildConfig.hubListenConnectionString, context);
String template = "{\"message\":{\"android\":{\"data\":{\"message\":\"{'Notification Hub test notification: ' + $(myTextProp)}\"}}}}";
hub.registerTemplate(token, "template-name", template);
shouldnt this be NotificationHubClient
instead of NotificationHub
? i get the error below
The type or namespace name 'NotificationHub' could not be found (are you missing a using directive or an assembly reference?)[CS0246](https://msdn.microsoft.com/query/roslyn.query?appId%3Droslyn%26k%3Dk%28CS0246%29)
// Create new notification hub with FCM v1 credentials
var hub = new NotificationHubDescription("hubname"); //returns type NotificationHubDescription
hub.FcmV1Credential = new FcmV1Credential("private-key", "project-id", "client-email");
hub = await namespaceManager.CreateNotificationHubAsync(hub); //also returns type NotificationHubDescription
// Create new Registration
var deviceToken = "device-token";
var tags = new HashSet<string> { "tag1", "tag2" };
FcmV1RegistrationDescription registration = await hub.CreateFcmV1NativeRegistrationAsync(deviceToken, tags);
// Send FCM v1 notification
var jsonBody = "{\"message\":{\"android\":{\"data\":{\"message\":\"Notification Hub test notification\"}}}}";
var n = new FcmV1Notification(jsonBody);
NotificationOutcome outcome = await hub.SendNotificationAsync(n, "tag");
hub
is of type NotificationHubDescription
, hub
should be of type NotificationHubClient
. How do we assign a NotificationHubDescription to a NotificationHubClient
Hi jayeshkv. In my case I already had the hub configured (with three parameters) in Azure portal. What I had to got an instance of the existing hub like this:
Microsoft.Azure.NotificationHubs.NotificationHubClient existingHub = new Microsoft.Azure.NotificationHubs.NotificationHubClient("StringConnecctionOfTheHub", "NameOfTheHub");
var result = await existingHub .CreateFcmV1NativeRegistrationAsync(token, tags); if (result != null) { regID = result.FcmV1RegistrationId; }
And it worked. It was a litthe confused because the code help assumes you have to create the hub, it was not my case.
I had to add the reference to:
// location unknown // Decompiled with ICSharpCode.Decompiler 8.1.1.7464
I hope this help.
It's bit confusing in terms of overall migration process. I have following question and if someone can answer those:
1. Assuming, the message template has changed between FCM and FCM1, does it affect to developers who are using cross platform notifications? (For example NotificationHubClient.SendTemplateNotificationAsync method which sends notification to Android or iOS device) R/. We are using multiplatform IDE Xamarin in our App. We made a test sending a message from Azure Android FCMv1 with the new template suggested by Azure: { "message": { "notification": { "body" : "message body"} } } and the message did not arrive to the emulator.
However, I set a break point to the first line, in the method which recieves the notification, and guest what, the notification arrived but because it has a different estructure, Azure interpretes it did not arrive. So, we made a change in the App an fix the App to recieves with the structure of FCM v1 { "message": { "notification": { "body" : "message body"} } } and after that, Azure now detects that the notification was successfully delivered. So, Azure is connected like a thread with the client App.
2. If the message template has changed between FCM and FCM v1 shouldn't the app be updated first to support this changed notification? R/. So, according what I typed in the above question the answer is Yes, you must change the App to be able to recieves messages with the new format.
3. The guide assumes that all users will be either on FCM or FCM v1. But in real life, some users will be on FCM and others on FCM v1 (because migration cannot be instanteneous). In such case, how this migration will work i.e. support gradual migration from FCM to FCM v1. R/. I think this depends on what you want to do and what you can do, I will tell you what are we going to do with this: a. We are going to changes the app for new installations register the tag - token in FCMv1 and not in the legacy. We must set a flag for example: FCMV1Installe = true b. We are going to changes the app, every time the app begins, we are going to check the flag FCMV1Installe if exists or is false, if so, we must apply the update suggested by Microsoft to move it from Legacy to FCMv1. c. The Code in out server that notify or send the message to Azure to notify is going to send two messages: --To the legacy way for the legacy clients. --To FCMv1 for the new a migrated client.
Did you see the linik: https://learn.microsoft.com/en-us/azure/notification-hubs/firebase-migration-sdk Is your app built with Xamarin?
@jporrasmi Thank you for the answer! More questions:
{message:{android:{data:{message:Notification Hub test notification}}}}
FCM/APM:
{genericMessage:{body:{data:{message:Notification Hub test notification}}}}
Yes, we are using XAMARIN! Earlier we had same template for both Android and iOS apps. With this change, we are moving Android to FCMV1 template and will keep iOS on old template.
Regarding migration, we took different approach:
There are more questions but it's for Microsoft.Azure.NotificationHubs
team.
Earlier we were using generic path operation for registration -
And now there is new code sample -
There is no information about how these two are different.
Also, Should this code have any effect of this migration? (I think no but there is no documentation to confirm this :?)
I also have a follow up question: Here is mentions to retrieve all registrations and installation to update them. What is the 'best' way to do this if you use installations as there is no way way to iterate the installations directly, only the registrations. Should we just use the GetAllRegistrations method and update installation using the registration directly?
Should we just use the GetAllRegistrations method and update installation using the registration directly?
That is exactly how we are doing it and it seems to be working.
How do you change the platform of a registration as it seems to be tied to the type of the object instead of a property of the registration (unlike an installation)?
Closing this issue for now, please reach out for support if you have further questions. Thank you! #please-close
- We fetch all registrations with GetAllRegistrations
- We filter the registrations and keep only the ones that contain a tag with "$InstallationId:xxxxx"
- We loop the registrations and perform a GetInstallationAsync by installationId
- We update the platform on the installation object: hubInstallation.Platform = NotificationPlatform.FcmV1;
- We update the installation: await _hubClient.CreateOrUpdateInstallationAsync(hubInstallation);
This method of converting GCM/FCM to FCMv1 by @dme-development worked for us
1. Assuming, the message template has changed between FCM and FCM1, does it affect to developers who are using cross platform notifications? (For example NotificationHubClient.SendTemplateNotificationAsync method which sends notification to Android or iOS device) R/. We are using multiplatform IDE Xamarin in our App. We made a test sending a message from Azure Android FCMv1 with the new template suggested by Azure: { "message": { "notification": { "body" : "message body"} } } and the message did not arrive to the emulator.
However, I set a break point to the first line, in the method which recieves the notification, and guest what, the notification arrived but because it has a different estructure, Azure interpretes it did not arrive. So, we made a change in the App an fix the App to recieves with the structure of FCM v1 { "message": { "notification": { "body" : "message body"} } } and after that, Azure now detects that the notification was successfully delivered. So, Azure is connected like a thread with the client App.
2. If the message template has changed between FCM and FCM v1 shouldn't the app be updated first to support this changed notification? R/. So, according what I typed in the above question the answer is Yes, you must change the App to be able to recieves messages with the new format.
3. The guide assumes that all users will be either on FCM or FCM v1. But in real life, some users will be on FCM and others on FCM v1 (because migration cannot be instanteneous). In such case, how this migration will work i.e. support gradual migration from FCM to FCM v1. R/. I think this depends on what you want to do and what you can do, I will tell you what are we going to do with this: a. We are going to changes the app for new installations register the tag - token in FCMv1 and not in the legacy. We must set a flag for example: FCMV1Installe = true b. We are going to changes the app, every time the app begins, we are going to check the flag FCMV1Installe if exists or is false, if so, we must apply the update suggested by Microsoft to move it from Legacy to FCMv1. c. The Code in out server that notify or send the message to Azure to notify is going to send two messages: --To the legacy way for the legacy clients. --To FCMv1 for the new a migrated client.
Did you see the linik: https://learn.microsoft.com/en-us/azure/notification-hubs/firebase-migration-sdk Is your app built with Xamarin?
1. Assuming, the message template has changed between FCM and FCM1, does it affect to developers who are using cross platform notifications? (For example NotificationHubClient.SendTemplateNotificationAsync method which sends notification to Android or iOS device) R/. We are using multiplatform IDE Xamarin in our App. We made a test sending a message from Azure Android FCMv1 with the new template suggested by Azure: { "message": { "notification": { "body" : "message body"} } } and the message did not arrive to the emulator.
However, I set a break point to the first line, in the method which recieves the notification, and guest what, the notification arrived but because it has a different estructure, Azure interpretes it did not arrive. So, we made a change in the App an fix the App to recieves with the structure of FCM v1 { "message": { "notification": { "body" : "message body"} } } and after that, Azure now detects that the notification was successfully delivered. So, Azure is connected like a thread with the client App.
2. If the message template has changed between FCM and FCM v1 shouldn't the app be updated first to support this changed notification? R/. So, according what I typed in the above question the answer is Yes, you must change the App to be able to recieves messages with the new format.
3. The guide assumes that all users will be either on FCM or FCM v1. But in real life, some users will be on FCM and others on FCM v1 (because migration cannot be instanteneous). In such case, how this migration will work i.e. support gradual migration from FCM to FCM v1. R/. I think this depends on what you want to do and what you can do, I will tell you what are we going to do with this: a. We are going to changes the app for new installations register the tag - token in FCMv1 and not in the legacy. We must set a flag for example: FCMV1Installe = true b. We are going to changes the app, every time the app begins, we are going to check the flag FCMV1Installe if exists or is false, if so, we must apply the update suggested by Microsoft to move it from Legacy to FCMv1. c. The Code in out server that notify or send the message to Azure to notify is going to send two messages: --To the legacy way for the legacy clients. --To FCMv1 for the new a migrated client.
Did you see the linik: https://learn.microsoft.com/en-us/azure/notification-hubs/firebase-migration-sdk Is your app built with Xamarin?
@dme-development do we need to have both NotificationHubClient and NotificationHub ? s_HubClient ??= new Microsoft.Azure.NotificationHubs.NotificationHubClient(ConnectionString, Path);
var instanceIdResult = await FirebaseInstallations.Instance.GetId();//await FirebaseInstanceId.Instance.GetInstanceId().AsAsync<IInstanceIdResult>();
var token = await FirebaseMessaging.Instance.GetToken();//instanceIdResult.Token;
var tags = App.PushNotificationRegistrationTags ?? new string[] { };
string regID = string.Empty;
var result = await s_HubClient.CreateFcmV1NativeRegistrationAsync(token.ToString(), tags);
if (result != null)
{
regID = result.FcmV1RegistrationId;
}
this is how I did, should need do NotificationHub registration also?, I use Xamarin forms
Subject: Issue with 403 Error When Sending Notifications
I am currently working on an implementation involving Azure Notification Hubs configured with Firebase. During testing, I encountered a problem when sending notifications. Specifically, I receive a 403 error message.
The FcmV1Notification
object allows us to include an Authorization header with a Bearer token generated by Google. However, when attempting to send a notification, I encounter an error indicating that multiple parameters cannot be sent in the Authorization header. This issue occurs despite providing the correct Google-generated token for authorization.
I would appreciate your assistance in resolving this issue at your earliest convenience.
public async Task SendMessage() { var hub = new NotificationHubClient(ListenConnectionString, "MYDETAPPcenter"); // string accessToken = await GenerateAccessToken(serviceAccountFile);//Generate for google // Msj JSON for FCM v1 var jsonBody = "{ \"message\": { \"notification\": { \"body\" : \"message body\"} } }"; var notification = new FcmV1Notification(jsonBody);
// notification.Headers.Add("Authorization", $"Bearer {accessToken}");
NotificationOutcome outcome = await hub.SendNotificationAsync(notification, "tag2");
if (outcome.Success == 0L)
{
}
}
Best regards,
Hello,
I am reading through the instructions to migrate from legacy FCM to the new FCMv1 and the following line is a bit unclear to me: "If the device registration happens on the server, you can fetch all registrations/installations and update them to FCMv1 on the server." This suggests that we would only need to change the type of the installation in the notification hub (without generating a new device token) to be able to send notifications. This also is in contradiction to what was said before: "After all existing devices have registered as FCM v1 devices, cease sending notifications to FCM legacy. Exclusively use FCM v1 for sending notifications at this point, and you’ll be fully migrated". This suggests that we need to keep using both systems while waiting for all devices to have a new installation/registration with a new device token for FCMv1.
Can it be documented more clearly what the recommended approach is to migrate the existing installation/registrations to the FCMv1
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.