我已经在我的WP7应用程序中实现了推送通知,并获得了用户发送通知的通道uris列表。我的问题出现在我开始发送通知时,如果任何设备/ uri断开连接/不活动,通知根本不会发送给其他活动用户。那么,我该如何处理这个问题呢? 提前致谢。
public Mainpage()
{
InitializeComponent();
if (IsolatedStorageSettings.ApplicationSettings.Contains("DeviceId"))
{
_deviceId = (Guid)IsolatedStorageSettings.ApplicationSettings["DeviceId"];
}
else
{
_deviceId = Guid.NewGuid();
IsolatedStorageSettings.ApplicationSettings["DeviceId"] = _deviceId;
}
SetupNotificationChannel();
}
private void SetupNotificationChannel()
{
_channel = HttpNotificationChannel.Find(ChannelName);
if (_channel == null)
{
_channel = new HttpNotificationChannel(ChannelName);
_channel.ChannelUriUpdated += ChannelUriUpdated;
_channel.ErrorOccurred += (s, e) => Deployment.Current.Dispatcher.BeginInvoke(() => ErrorOccurred(e));
_channel.Open();
}
else
{
RegisterForNotifications();
}
}
private void ErrorOccurred(NotificationChannelErrorEventArgs e)
{
MessageBox.Show("ERROR:" + e.Message);
}
void ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
_channel = HttpNotificationChannel.Find(ChannelName);
if (!_channel.IsShellTileBound)
{
Collection<Uri> ListOfAllowedDomains = new Collection<Uri> { new Uri("http://www.abcdef.com") };
_channel.BindToShellTile(ListOfAllowedDomains);
}
if (!_channel.IsShellToastBound)
{
_channel.BindToShellToast();
}
RegisterForNotifications();
}
private void RegisterForNotifications()
{
RegisterWithNotificationService();
_channel.ShellToastNotificationReceived += (s, e) => Deployment.Current.Dispatcher.BeginInvoke(() => ToastReceived(e));
//_channel.HttpNotificationReceived += (s, e) => Deployment.Current.Dispatcher.BeginInvoke(() => HttpNotificationReceived(e));
_channel.ErrorOccurred += (s, e) => Deployment.Current.Dispatcher.BeginInvoke(() => ErrorOccurred(e));
}
private void RegisterWithNotificationService()
{
ServiceProxy.WCFServiceClient svc = new ServiceProxy.WCFServiceClient();
svc.SubscribeCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(svc_SubscribeCompleted);
svc.SubscribeAsync(IsolatedStorageSettings.ApplicationSettings["DeviceId"].ToString(), _channel.ChannelUri.ToString());
}
private void ToastReceived(NotificationEventArgs e)
{
MessageBox.Show(string.Format(e.Collection["wp:Text1"] + "\n" + e.Collection["wp:Text2"]));
}