我有一个为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"+": " + "\"}}";
答案 0 :(得分:0)
这种方法对我有用:
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");
}
}