簡體   English   中英

我想發送推送通知IOS,集線器azure

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM