我有一个活动流系统,某种类型的社交网络,该系统已启动并正在运行,现在我想向其中添加推送通知。 为此,我选择了azure推送通知中心,并且每个设备的通知已经正常运行 这是我用于Android和iOS设备注册的代码
Android代码
async Task SendRegistrationToServerAsync(string token)
{
try
{
// Formats: https://firebase.google.com/docs/cloud-messaging/concept-options
// The "notification" format will automatically displayed in the notification center if the
// app is not in the foreground.
const string templateBodyFCM =
"{" +
"\"notification\" : {" +
"\"body\" : \"$(messageParam)\"," +
"\"title\" : \"ActivityStream\"," +
"\"icon\" : \"myicon\" }" +
"}";
var templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyFCM}
};
var client = new MobileServiceClient(XamUNotif.App.MobileServiceUrl);
var push = client.GetPush();
await push.RegisterAsync(token, templates);
// Push object contains installation ID afterwards.
Console.WriteLine(push.InstallationId.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Debugger.Break();
}
}
iOS代码
async Task SendRegistrationToServerAsync(NSData deviceToken)
{
// This is the template/payload used by iOS. It contains the "messageParam"
// that will be replaced by our service.
const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}";
var templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyAPNS}
};
var client = new MobileServiceClient(XamUNotif.App.MobileServiceUrl);
await client.GetPush().RegisterAsync(deviceToken, templates);
}
现在,我的目标是向所有订阅X活动流对象的用户发送推送通知,这是我想做什么的伪代码
void SendPushNotification(List<Guid> ObjectFollowers)
{
Backend.SendPushNotifications(ObjectFollowers)
}
我知道上面的代码会起作用,但是我知道这不是正确的方法,正确的方法应该是使用标签,任何人都可以指向任何代码片段示例来订阅标签并将通知发送给标签?