有很多同学抱怨MPNS的各种问题,其中包括服务超时、返回各种错误代码不知如何处理等等。。今天我用一点时间来为大家介绍下如何处理和操作咱们的MPNS。

首先为大家明确一个问题,Microsoft Push Notification Service (MPNS) 是执行的异步推送。今天将介绍如何使用高效的服务将我们的推送信息发送至云端最终发送到 Windows Phone 手机。

第一 如何设置发送超时

对于超时时间我建议大家设置为 15秒。例如:你使用的 ASP.NET 进行数据推送时,建立 WebRequest 对象设置超时时间

HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
request.Timeout = 15000;

第二 处理推送通道的更新

当你的客户端程序发现推送通道更新后,应用一定要将最新的推送通道 URL 更新到你的服务器端。要保证您的服务器端的推送通道是最新的。建议你可以使用 device ID 与推送通道进行匹配,如果发现推送通道的URL更新就立刻进行推送通道更新,服务器通过device ID进行判断是,新用户注册还是已有用户的推送通道更新。

Windows Phone 的官方资料中提供了如何建立一个接受推送消息的应用代码示例,其中包括了如何处理,推送通道更新事件。您可以参考 如何发送和接收 Windows Phone 的磁贴通知 了解如何使用PushChannel_ChannelUriUpdated方法。(另:推送通道长度也许会超过 1024 characters)

第三 使用已验证的 Web 服务以发送 Windows Phone 的推送通知

使用MPNS认证端,如果你的推送服务针对一台WindowsPhone设备24小时内推送消息数量超过500条,或者您想更安全的推送消息。另使用没有MPNS验证的终端进行推送,每日的推送限额是500条/每个device。

如何设置 MPNS验证的终端。

设置已验证的 Web 服务以发送 Windows Phone 的推送通知

No-quota push notifications using a root Certificate Authority

另外,如果你的推送服务超过每天500条的推送对每台设备,有一点您就需要额外的考虑用户的手机电量是使用情况了。

第四 根据MPNS返回的代码进行处理

通常移动设备的网络都会变化的,了解 Windows Phone 网络连接的变换状态判断规则:设备状态的过度流程

你将推送服务发送至MPNS,随后MPNS会将设备的信息返回,你需要观察设备状态(Windows Phone 的推送通知服务响应代码),在进行处理我推荐一些做法如下:

Response code Notification status Device connection status Subscription status Recommendations
200 OK QueueFull Connect Active 建议从新发送通知,但是可以设置一个重发时间间隔,如果还收到同样错误代码尝试延长重试时间:4 – 8 – 16 分钟以此类推到32分钟。
200 OK QueueFull Temp Disconnected Active 建议从新发送通知,但是可以设置一个重发时间间隔,如果还收到同样错误代码尝试延长重试时间:2 – 4 – 8 分钟以此类推到 24 小时。
404 Not Found Dropped * Any Connection Status Expired 不需要再尝试发送消息了,因为这个推送通道已经不存在了。

412 Precondition Failed

Dropped Disconnected N/A 建议每小时尝试一次从新发送,但是如果超过24小时还是返回相同错误,就停止推送。
503 N/A N/A N/A 建议从新发送通知,但是可以设置一个重发时间间隔,如果还收到同样错误代码尝试延长重试时间:5 – 10 – 20 – 40 秒以此类推到30分钟。

更多资源请参考:

发送 Windows Phone 的推送通知

Windows Phone 的推送通知服务响应代码

如何获得 Microsoft Push Notification Service(MPNS)的最佳体验的更多相关文章

  1. Microsoft Push Notification Service(MPNS)的最佳体验

    如何获得 Microsoft Push Notification Service(MPNS)的最佳体验 有很多同学抱怨MPNS的各种问题,其中包括服务超时.返回各种错误代码不知如何处理等等..今天我用 ...

  2. Provider Communication with Apple Push Notification Service

    This chapter describes the interfaces that providers use for communication with Apple Push Notificat ...

  3. (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送

    在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送 From: http://saeapns.sinaapp.com/doc.html 1,在 ...

  4. 陌陌架构分享 – Apple Push Notification Service

    http://blog.latermoon.com/?p=878 先描述下基本概念,标准的iPhone应用是没有后台运行的,要实现实时推送消息到手机,需要借助Apple提供的APNS服务. iPhon ...

  5. Missing Push Notification Entitlement 问题

    最近打包上传是遇到一个问题: 描述: Missing Push Notification Entitlement - Your app includes an API for Apple's Push ...

  6. iOS上简单推送通知(Push Notification)的实现

    iOS上简单推送通知(Push Notification)的实现 根据这篇很好的教程(http://www.raywenderlich.com/3443/apple-push-notification ...

  7. apple 官方文档 Push Notification Programming

    iOS Developer LibraryDeveloper Search Local and Push Notification Programming Guide PDF Table of Con ...

  8. (转)How to build an Apple Push Notification provider server (tutorial)

    转自:https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ ...

  9. (转)Apple Push Notification Services in iOS 6 Tutorial: Part 2/2

    转自:http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2 Upda ...

随机推荐

  1. DESeq2包

    1)简介: DESeq2-package: for differential analysis of count data(对count data 做差异分析) 2)安装 if("DESeq ...

  2. 《Visual C++开发实战1200例 第1卷》扫描版[PDF]

    [内容简介:] <Visual C++开发实战1200例(第1卷)>是“软件开发实战1200例”丛书之一.<Visual C++开发实战1200例(第1卷)>,编程实例的四库全 ...

  3. Required String parameter ' ' is not present

    Required String parameter ' ' is not present 报错原因: url中的参数错误. 解决方法: 1.修正url中的参数的值. 2.在Controller层中的@ ...

  4. java并发:volatile关键字

    java并发需要保证原子性,可见性,有序性. http://www.cnblogs.com/expiator/p/9226775.html 一.volatile关键字作用如下: 1.volatile关 ...

  5. org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]

    运行servlet程序报错: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Cat ...

  6. luoguP1080 国王游戏 (贪心+高精度)

    题目链接:https://www.luogu.org/problemnew/show/P1080 参考:https://www.luogu.org/problemnew/solution/P1080 ...

  7. 解读超轻量级DI容器-Guice与Spring框架的区别【转载】

    依赖注入,DI(Dependency Injection),它的作用自然不必多说,提及DI容器,例如spring,picoContainer,EJB容器等等,近日,google诞生了更轻巧的DI容器… ...

  8. [leetcode]277. Find the Celebrity 找名人

    Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist o ...

  9. Django配置Bootstrap, js

    1.首先在APP目录下创建一个static文件夹 如图: # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'dj ...

  10. workerman使用

    1.start_timer.php(boc) <?php use \Workerman\Worker; use \Workerman\Lib\Timer; require_once '/var/ ...