2

我很难实现这个目标。我正在开发一个PhoneGap 应用程序,并将它部署到Android、iOS 和Windows Phone 上。

我能够毫无问题地使用 Apple Notification Service (APN) 和 Google Cloud Messaging,但我在尝试对我的 Windows Phone 应用程序做同样的事情时遇到了非常糟糕的事情。

与 APN 和 GCM 不同,我找不到生成一些代码或下载一些证书以将我的应用程序与推送通知服务集成的地方。

我正在尝试使用此服务通过 PHP http://phpwindowsphonepush.codeplex.com/向 Windows Phone 发送推送通知

该示例向我展示了这一点$uri="http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798"; //uri sended by Microsoft plateform,但我如何注册到他们的平台以获得这样的 URI?

另外,这个 PHP Windows Phone Push 是在 Windows Phone 上发送 toast 和 tile 通知的正确选择吗?文档非常混乱,不清楚如何配置服务器和本机代码应用程序,我迷路了。

4

1 回答 1

3

该 URI 称为通知通道,它是 APNS 设备令牌和 GCM 注册 ID 的 MPNS 等效项。您可以在您的 Windows Phone 应用程序代码中获取它:

public MainPage()
{
    /// Holds the push channel that is created or found.
    HttpNotificationChannel pushChannel;

    // The name of our push channel.
    string channelName = "ToastSampleChannel";

    InitializeComponent();

    // 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);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        pushChannel.Open();

        // Bind this new channel for toast events.
        pushChannel.BindToShellToast();

    }
    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);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        // 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());
        MessageBox.Show(String.Format("Channel Uri is {0}",
            pushChannel.ChannelUri.ToString()));

    }
}

您不必验证您的网络服务(未经验证的网络服务可以每天每台设备发送 500 条消息),但建议这样做:

我们建议设置经过身份验证的 Web 服务以将您的通知发送到推送通知服务,因为通过 HTTPS 接口进行通信以提高安全性。经过身份验证的 Web 服务对它们可以发送的推送通知的数量没有每日限制。另一方面,未经身份验证的 Web 服务以每天每个订阅 500 条推送通知的速度受到限制。有关详细信息,请参阅设置经过身份验证的 Web 服务以发送 Windows Phone 的推送通知。

相关链接:

为 Windows Phone 发送推送通知

设置经过身份验证的 Web 服务以发送 Windows Phone 的推送通知

于 2013-03-29T13:43:32.447 回答