为多个用户发送API通知OneSignal

时间:2016-05-15 14:01:36

标签: onesignal

我尝试将OneSignal的API通知发送到API REST,当我发送给唯一用户时,它的工作正常,但是当Json中有多个用户时,会发送通知独特的用户。

My JSON (listOnesignal):[{"key":"user","relation":"=","value":"YAlBcuwiOJ"},{"key":"user","relation":"=","value":"MSoVMRxzbh"}]    

var jsonBody = { 
                  app_id: "appid", 
                  android_background_data: true,
                  tags: listOneSignal,
                  data: {anything}
    };

2 个答案:

答案 0 :(得分:4)

您需要在每个条目之间添加OR运算符,默认情况下使用AND

[{"key":"user","relation":"=","value":"YAlBcuwiOJ"},
 {"operator": "OR"},
 {"key":"user","relation":"=","value":"MSoVMRxzbh"}]

请注意,每个REST API调用在OR字段上限制为200个条目(包括tags' s)。如果您需要一次定位更多设备,则可以使用include_player_ids,而最多可以发送2,000个。

有关详情,请参阅OneSignal create notification REST API文档页面。

答案 1 :(得分:1)

如果有人使用OneSignal CSharp SDK,这就是你可以做同样事情的方法(虽然这个例子使用标签代替玩家ID):

IList<INotificationFilter> filters = new List<INotificationFilter>();

foreach (var tag in tagList)
{
    var filter = new NotificationFilterField
    {
        Field = NotificationFilterFieldTypeEnum.Tag,
        Key = "tag_id",
        Value = tag,
        Relation = "="
    };

    if (filters.Count > 0)
        filters.Add(new NotificationFilterOperator { Operator = "OR" });

    filters.Add(filter);
}

var client = new OneSignalClient("...");

var options = new NotificationCreateOptions
{
    AppId = new Guid("..."),
    Filters = filters
};

options.Contents.Add(...);
client.Notifications.Create(options);