Reputation: 575
I have tried to send push notifications to users, luckily I got it but my requirement is need to send push notifications to specific user, I have tried a lot but not luck.
Sample Code for sending notifications to the user:
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionString, "HubName");
await hub.SendAppleNativeNotificationAsync(alertJson, userId.ToString());
When I tried the above code, I am not receiving any push notifications. If we remove userId in above code push notifications is send to the user successfully but notification is send to all registered users. My actual requirement is sending push notification to specific user.
Upvotes: 0
Views: 1489
Reputation: 18465
According to your description, I would recommend you checking the Device Registrations under your azure notification hub to verify your userId
(a single tag for the specific user) is correct and belongs to your expected user.
For programmatic retrieving registrations with tags, you could refer to this tutorial. For a simple way, you could leverage Server Explorer from Visual Studio, choose your notification hub, then view and manage all the registrations in your hub as follows:
Also, you could leverage "Test Send" for testing. For more details, you could refer to the Verify registrations section under Self-diagnose tips.
In general, we use the Registrations model for device registration in a simple way. Also, we could use Installations pattern model that makes it easy to do individual pushes, and a system tag "$InstallationId:[installationId]" is automatically added with each installation based registration. So you can call a send to this tag to target a specific device without having to do any additional coding. But the client .NET SDK does not support the installations model and you need to use the notification hubs REST API for now. For more details, you could refer to Registration management.
Upvotes: 1