In my .NET8 MAUI
i Want to add the push notification via Azure Notification Hub. Reading the documentation, I wrote this code to create an installation in the hub:
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
string token = deviceToken.GetBase64EncodedString(NSDataBase64EncodingOptions.None)
var deviceInstallation = new
{
InstallationId = token,
Platform = "apns"
};
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("x-ms-version", "2015-01");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization",
CreateToken($"https://languageinuse.servicebus.windows.net",
"DefaultListenSharedAccessSignature", Constants.PushNotificationSecret));
var r = await httpClient.PutAsJsonAsync($"https://languageinuse.servicebus.windows.net/" +
$"app/installations/{deviceInstallation.InstallationId}?api-version=2015-01",
deviceInstallation);
}
The result is a `Bad request and this is the result
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
Strict-Transport-Security: max-age=2592000
trackingid: 979df88e-a15e-4215-8f76-d77c9d23e0b3
x-ms-correlation-request-id: d1ca2a1e-5b1a-499c-86cf-f9f3f61bb6f1
Server: Kestrel
Date: Mon, 26 Feb 2024 23:43:20 GMT
Strict-Transport-Security: max-age=2592000
trackingid: 979df88e-a15e-4215-8f76-d77c9d23e0b3
Content-Type: application/xml
x-ms-correlation-request-id: d1ca2a1e-5b1a-499c-86cf-f9f3f61bb6f1
}}
I don't understand where the problem is. Is the PushChannel
required in the deviceInstallation
? If yes, how can I get one? Is the token
correct in this request?