![](/img/trans.png)
[英]Can I use Windows Azure Notification Hub to send push notification from Windows 8 to Windows Phone 8?
[英]I want to send a push notification IOS, hub azure
我有一個專為Android構建的天藍色通知中心。 我正在為IOS進行構建。
這些是我需要在通知中發送的數據,它們已經發送至Android:
// Android payload
JObject data = new JObject();
data.Add("Id", notification.Id);
data.Add("Descricao", notification.Descricao);
data.Add("Tipo", notification.Tipo);
data.Add("Id_usuario", notification.Id_usuario);
//data.Add("Informacao", notification.Informacao);
data.Add("Informacao", notification.Informacao);
data.Add("Status", notification.Status);
如何將這些數據放入IOS的推送通知?
var apnsNotification = "{\"aps\":{\"alert\":\"" + "Some Title"+": " + "\"}}";
此方法對我有用:
public static async void sendPushNotificationApns(ApiController controller, DataObjects.Notification notification)
{
// Get the settings for the server project.
HttpConfiguration config = controller.Configuration;
MobileAppSettingsDictionary settings =
controller.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings();
// Get the Notification Hubs credentials for the Mobile App.
string notificationHubName = settings.NotificationHubName;
string notificationHubConnection = settings
.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;
// Create a new Notification Hub client.
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName);
var apnsNotification = "{\"aps\":{\"alert\":\"" + notification.Descricao + "\"},\"Id\":\"" + notification.Id +
"\",\"Tipo\":\"" + notification.Tipo + "\",\"Id_usuario\":\"" + notification.Id_usuario +
"\",\"Informacao\":\"" + notification.Informacao +
"\",\"Status\":\"" + notification.Status + "\"}";
try
{
// Send the push notification and log the results.
String tag = "_UserId:" + notification.Id_usuario;
var result = await hub.SendAppleNativeNotificationAsync(apnsNotification, tag);
// Write the success result to the logs.
config.Services.GetTraceWriter().Info(result.State.ToString());
}
catch (System.Exception ex)
{
// Write the failure result to the logs.
config.Services.GetTraceWriter().Error(ex.Message, null, "Push.SendAsync Error");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.