我正在从Azure Notification中心发送推送通知。我想要点击收到Toast推送通知的特定页面。我收到推送通知但无法导航到特定页面。
这是我的插入代码:
function insert(item, user, request) {
var payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual>' +
'<binding template="ToastText01"> <text id="1">' +
item.subject + '</text></binding></visual></toast>';
request.execute({
success: function () {
// If the insert succeeds, send a notification.
push.wns.send(null, payload, 'wns/toast', {
success: function (pushResponse) {
console.log("Sent push:", pushResponse);
request.respond();
},
error: function (pushResponse) {
console.log("Error Sending push:", pushResponse);
request.respond(500, { error: pushResponse });
}
});
}
});
}
任何人都可以帮忙吗?
答案 0 :(得分:0)
这里有很多步骤,你没有详细说明你的问题。我试图完全解释这个概念,任何可能需要整个事情的人。请务必先设置本文中的所有步骤:https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-windows-phone-get-started-push/
首先,您需要发送包含要加载的页面的推送通知。因此,我们假设您有一个页面,其中显示了有关项目的一些详细信息。当您收到推送通知时,它会自动打开该项目。你可以发送一个有效载荷,如:
var payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual>' +
'<binding template="ToastText01"> <text id="1">' +
item.id + '</text></binding></visual></toast>';
然后您需要响应推送通知。您可以在此处查看文档页面:https://msdn.microsoft.com/en-us/library/hh221550.aspx
您的设置代码如下所示:
ShellToastNotificationReceived +=
new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);
public static HttpNotificationChannel CurrentChannel { get; private set; }
// This is from the tutorial linked in the first paragraph
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("MyPushChannel");
CurrentChannel.Open();
CurrentChannel.BindToShellToast();
}
CurrentChannel.ChannelUriUpdated +=
new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
// Register for notifications using the new channel
await MobileService.GetPush()
.RegisterNativeAsync(CurrentChannel.ChannelUri.ToString());
});
CurrentChannel.ShellToastNotificationReceived +=
new EventHandler<NotificationEventArgs(async (o, args) =>
{
RootFrame.Navigate(new Uri("/ItemPage.xaml"), args.Collection['1']);
});
}
我还没有对这些代码进行测试,但它应该足以让您指出正确的方向。基本上,
请务必查看有关导航的本教程:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx