注意:我使用 parse 仅发送推送通知,而不是作为数据存储,它也提供。
所以用了一段时间后发现如下
- 首先需要这个。
ParseClient.Initialize('ParseApplicationKey', 'ParseDotNetKey');。当您第一次加载应用程序时,您应该将它的代码放在首位。 IE。 startup.cs 或 global.asax.cs 这是一炮而红。
- 发送推送使用 parse.com 中的
Installation 类/表。您可以将自己的列添加到类中。我添加了ContactId,以便我可以查询 id 以发送推送。
- 您需要先启用
Client Push Enabled?,然后才能发送推送。否则你会得到像Client-initiated push isn't enabled这样的错误
- 现在发送推送通知
// sending to all with only alert message
var parsePush = new ParsePush();
parsePush.Alert="hi";
await parsePush.SendAsync();
// sending to all with your own data
parsePush.Data= new Dictionary<string, object>
{
{"alert", message},// this is replacement for parsePush.Alert
{"sound", "notify.caf"},// for ios
{"badge", "Increment"}// for ios notification count increment on icon
};
await parsePush.SendAsync();
// Sending with custom data, you can add your own properties in the
// dictionary and send, which will be received by the mobile devices
{"reference_type", referenceType}// add to dictionary
{"reference_id", referenceType}
// adding query/conditions
int[] smartusers={1,2,3,4,5};
parsePush.Query = new ParseQuery<ParseInstallation>()
.Where(i => smartusers.Contains(i.Get<int>("ContactID")));
// ContactID is a propery in ParseInstallation, that i added
还有其他定位通知的方法
https://parse.com/docs/dotnet/guide#push-notifications-sending-pushes
更多信息https://parse.com/docs/dotnet/guide#push-notifications