我已经写了一个Azure函数并将其输出连接到通知中心,使用APNS发送推送通知。 只要我将通知发送到所有已注册的设备,它就可以正常工作,但是我不知道如何使用标签来定向发送通知给特定用户。 如果我尝试使用标签,则会出现错误消息,该消息说“Exception while executing function: Functions.SendSinglePushNotification. Microsoft.Azure.WebJobs.Host: Error while handling parameter notification after function returned:. Microsoft.Azure.NotificationHubs: notification.Tag property should be 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); 但是这并不起作用。我该怎么做才能实现它呢?
非常感谢,祝好!