我正在尝试使用 WP7.1 中的推送通知。我创建了类和一些 php 类。该示例适用于所有通知类型,但我的问题是 UriChannel。通过我的简单示例,我必须在 php 代码中手动编写 URI 通道。
安装我的应用程序的所有设备的 uri 通道是否唯一?
如何将 Uri Channel 发送到我的服务器?
谢谢。
这是我的代码:
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "LiveTileChannel";
// Costruttore
public MainPage()
{
InitializeComponent();
CreatePushChannel();
}
private void CreatePushChannel()
{
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(pushChannel_HttpNotificationReceived);
pushChannel.Open();
// Bind this new channel for Tile events.
pushChannel.BindToShellTile();
pushChannel.BindToShellToast();
connessioneTxt.Text = "Connessione avvenuta";
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(pushChannel_HttpNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
uriTxt.Text=pushChannel.ChannelUri.ToString();
connessioneTxt.Text = "Connessione già avvenuta";
}
}
void pushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string message;
using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
{
message = reader.ReadToEnd();
}
Dispatcher.BeginInvoke(() => rawTxt.Text = String.Format("Received Notification {0}:\n{1}",
DateTime.Now.ToShortTimeString(), message)
);
}
/// Event handler for when the Push Channel Uri changes.
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
uriTxt.Text = pushChannel.ChannelUri.ToString();
});
}
// Event handler for when a Push Notification error occurs.
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
// Error handling logic for your particular application would be here.
Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)));
}
void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
System.Diagnostics.Debug.WriteLine("notifica aperta");
}
}
还有一个树 php 示例: