WP和iOS的Azure通知 [英] Azure Notifications to WP and iOS

查看:64
本文介绍了WP和iOS的Azure通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用Azure通知中心将消息发送到Windows Phone和iOS设备.问题在于,如果两者被调用,它们将起作用,但是如果两者都被调用,则它们将不起作用.

My app uses an Azure Notification Hub to send messages to both Windows Phone and iOS devices. The problem is that they work if one is called, but it doesn't work if both are called.

例如,如果我从iOS模拟器向iOS设备发送消息,则以下代码可以正常工作并显示通知.

For example, If I send a message to an iOS device from my iOS emulator, the following code works fine and the notification appears.

var toast = PrepareMpnsToastPayload("myapp", notificationText);
var appleToast = PrepareAppleToastPayload("myapp", notificationText);

//await NotificationHelper.Instance.Hub.SendMpnsNativeNotificationAsync(toast, userTag);
await NotificationHelper.Instance.Hub.SendAppleNativeNotificationAsync(appleToast, userTag);

但是,如果我取消注释SendMpns ..()行,则通知永远不会到达Apple设备.在通过远程调试逐步执行此代码时,似乎未返回对SendMpns ..()的调用.我越过它,它就恢复了..并且它下面的SendApple ..()调用上的断点再也不会受到攻击.

However, if I uncomment the SendMpns..() line, the notification never gets to the apple device. When stepping through this code with remote debugging, the call to SendMpns..() doesn't seem to return. I step over it and it just resumes.. and the breakpoint on the SendApple..() call below it never gets hit.

这与Windows Phone Mpns线路相同(在没有Apple呼叫的情况下也可以正常工作).

This works the same with the Windows Phone Mpns line (works fine without the apple call).

当我不知道他们在使用什么设备时,应该如何向用户发送警报?我只想将通知发送给所有类型.任何指针将不胜感激.

How am I supposed to send an alert to a user when I don't know what device they are on? I just want to send the notification to all types. Any pointers would be greatly appreciated.

删除await()的以下答案确实有效.但是,由于我现在已对通知中心进行了身份验证,因此我需要捕获该调用的返回值,以便可以查看是否已过期又需要获取另一个身份验证令牌!

The below answers of removing await() did work. However as I now have authenticated notification hub I need to capture the return value of the call so I can see if I need to get another auth token if it has expired!

推荐答案

如果发布的代码作为普通的控制台应用程序运行,那么我们应该等待任务完成.最简单的方法是删除await并针对xAsync()方法返回的Task对象调用Wait():

If posted code runs as trivial console application then we should wait for tasks to be completed. Easiest way to do so is removing await and calling Wait() against Task object returned by xAsync() methods:

NotificationHelper.Instance.Hub.SendMpnsNativeNotificationAsync(toast, userTag).Wait();
NotificationHelper.Instance.Hub.SendAppleNativeNotificationAsync(appleToast, userTag).Wait();

这篇关于WP和iOS的Azure通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆