I'm trying to figure out the best way to handle this scenario.
I have an MVC back end in Azure that has a bunch of end points for my app. I want to add another end point to handle sending iOS Push Notifications to users.
I am handling storing their device tokens, so my though was to just use PushSharp and loop over each token and push the appropriate token to the user. That works great locally, but I can't seem to get PushSharp to work in Azure. I've seen this solution here:
However I am unsure what the ServiceDefinition.csdef
file is and how that would be incorporated into my MVC solution.
I've started researching Azure Notification Hub but I'm not sure it can do what I need. I'm just looking for a simple solution in C# that can be hosted in Azure(ASP.NET MVC) where I can loop over a group of device tokens and push notifications.
If you already have Azure-hosted MVC application which takes and stores device tokens from end user iOS applications, then you could just create Service Bus namespace and Notification Hub in it, upload APNS certificate, and then your MVC application is able to register tokens and send notifications using Microsoft.ServiceBus.dll.
Here is very basic code sample:
var notificationHubClint = NotificationHubClient.CreateClientFromConnectionString("{connection string from the portal}", "{your hub name}");
// Register device token with notification hub. Call it when you get device token from iOS app first time.
var registration = await notificationHubClint.CreateAppleNativeRegistrationAsync("{device token}",new []{"SomeUserId"});
// You can modify properties or refresh device token and then update registration
registration.DeviceToken = "{new token}";
registration.Tags.Add("{new tag}");
await notificationHubClint.UpdateRegistrationAsync(registration);
// Send notification. Call when you want to send notification to user.
await notificationHubClint.SendAppleNativeNotificationAsync("{your message}","some user id");
Here I used tag to target the message the particular user. If you call just SendAppleNativeNotificationAsync("{your message}"), then message will be delivered to all users. Learn more about tags and tag expressions to make your sends efficient.