我已经跟随过那里的教程,我已经想出了这个......
这是一种设备注册方法,使用Microsoft.WindowsAzure.MobileServices.MobileServiceClient.RegisterAsync,它应该将设备令牌发送到服务器并向Azure Notification Hub注册。
这是我的代码:
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 token = deviceToken.Description.Trim('<', '>').Replace(" ", "").ToUpperInvariant();
var client = new MobileServiceClient(App.MobileServiceUrl);
var push = client.GetPush();
// token = "530FE16E53C9BCC93FC41C3A1AFB6FCE41F9078F1AC82D1C70B019E3B798CDD6"
// Error Happens Here - Line Below
await push.RegisterNativeAsync(token);
}
抛出
Newtonsoft.Json.JsonReaderException
解析值时遇到意外的字符:&lt;。路径'',第0行,第0位。
答案 0 :(得分:0)
看起来你的字符串中有一些不需要的字符。 请尝试以下代码:
var DeviceToken = deviceToken.Description;
if (!string.IsNullOrWhiteSpace(DeviceToken))
{
DeviceToken = DeviceToken.Trim('<').Trim('>');
}
让我知道它是否有帮助:)