Windows Azure ServiceBus Push Notifications APNS A

2019-07-04 00:45发布

问题:

I am building an application hosted on windows azure which will send messages to users on iphones through the apns. I am using a service bus notification hub rather than a mobile service as I have an existing persistence infrastructure using RavenDB and queues.

Say this is my notification service's send to apple method:

public async void SendAppleNotificationAsync(INotification notification)
        {            
            var hub = NotificationHubClient.CreateClientFromConnectionString(
                _configService.Get<NotificationConfig>().ConnectionString, 
                _configService.Get<NotificationConfig>().Hub);

            var appleNotification = new AppleNotification(notification.ToJsonString(), new DateTime());

            await hub.SendNotificationAsync(appleNotification);
        }

What I am unable to work out is how to send a notification to a specific device, given I have the user's device token from apple stored in my server side application.

I was hoping the api had a method like this:

var appleNotification = new AppleNotification(deviceToken, notification.ToJsonString(), new DateTime());

But I don't seem to be able to find any reference to targeting a specific device.

Am I missing something fundamental to the picture?

回答1:

Notification Hubs can be used to send out bulk notifications to groups of users, or to single users. It is basically a publish/subscribe model. The client subscribes to a topic and the server publishes notifications to that topic. A client might subscribe to a broad topic "promotions" or a narrow topic "user:123456". This article gives example code and a walkthrough of using Notification Hubs to send a message to a single client.

http://www.windowsazure.com/en-us/documentation/articles/notification-hubs-aspnet-notify-users/