gpt4 book ai didi

ios - Azure函数: send notification to specific users

转载 作者:可可西里 更新时间:2023-11-01 06:13:21 25 4
gpt4 key购买 nike

我编写了一个 Azure 函数,并将输出连接到通知中心,以使用 APNS 发送推送通知。只要我将通知发送到所有注册的设备,它就可以正常工作,但我不知道如何使用标签来寻址特定用户。如果我尝试使用标签,我会收到一条错误消息,显示“执行函数时出现异常:Functions.SendSinglePushNotification。Microsoft.Azure.WebJobs.Host:函数返回后处理参数通知时出错:。Microsoft.Azure.NotificationHubs:通知。标记属性应为 null。”

这是我到目前为止的代码:

#r "Microsoft.Azure.NotificationHubs"
#r "Newtonsoft.Json"


using System;
using Microsoft.Azure.NotificationHubs;
using Newtonsoft.Json;using
Microsoft.Azure.WebJobs.Host.Bindings.Runtime;

public static void Run(HttpRequestMessage req, TraceWriter log,Binder
binder, out AppleNotification notification)
{
string user = "Test";
string tagExpression = "Test";
string userTag = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "userid", true) == 0)
.Value;

string apnsNotificationPayload = "{\"aps\": {\"alert\": \"Test: (" + user + ")\" }}";
notification = new AppleNotification(apnsNotificationPayload);
}

我试图使用 notification = new
AppleNotification(apnsNotificationPayload,tagExpression);但这不起作用。我怎样才能实现这一目标?

非常感谢并致以最诚挚的问候

最佳答案

我也有类似的问题。最终,对我有用的是手动构建通知客户端。我正在 Visual Studio 中开发函数,因此我的代码与您的略有不同。

    [FunctionName("MyFunction")]
public static async Task Run([ServiceBusTrigger("queuename", AccessRights.Listen, Connection =
"<connection-settings-name>")] string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");

var notificationHubSas = "<DefaultFullSharedAccessSignature from Azure portal>";
var notificationHubName = "myhub";
var nhClient = NotificationHubClient.CreateClientFromConnectionString(notificationHubSas, notificationHubName);
var tags = "";
await nhClient.SendTemplateNotificationAsync(<notification payload>, tags);
}

关于ios - Azure函数: send notification to specific users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42962203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com