Push模块管理推送消息功能,可以实现在线、离线的消息推送,通过plus.push可获取推送 ...
<div id="article_content" class="article_content clearfix"><link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="htmledit_views">
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">方法:</span></strong></span></h2>
<ul><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.addEventListener">addEventListener</a>: 添加推送消息事件监听器</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.clear">clear</a>: 清空所有推送消息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.createMessage">createMessage</a>: 创建本地消息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.getAllMessage">getAllMessage</a>: 获取所有推送消息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.getClientInfo">getClientInfo</a>: 获取客户端推送标识信息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.getClientInfoAsync">getClientInfoAsync</a>: 异步获取客户端推送标识信息</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.setAutoNotification">setAutoNotification</a>: 设置程序是否将消息显示在系统消息中心</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.remove">remove</a>: 删除推送消息</li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">对象:</span></strong></span></h2>
<ul><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.ClientInfo">ClientInfo</a>: JSON对象,获取的客户端标识信息</li><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.PushMessage">PushMessage</a>: JSON对象,推送消息对象</li><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.MessageOptions">MessageOptions</a>: JSON对象,获客户端创建本地消息的参数</li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">回调方法:</span></strong></span></h2>
<ul><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.PushReceiveCallback">PushReceiveCallback</a>: 客户端接收到推送消息的回调函数</li><li><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.PushClickCallback">PushClickCallback</a>: 用户点击推送消息事件的回调函数</li><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.ClientInfoSuccessCallback">ClientInfoSuccessCallback</a>: 异步获取客户端推送标识信息成功的回调函数</li><li><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.ClientInfoErrorCallback">ClientInfoErrorCallback</a>: 异步获取客户端推送标识信息失败的回调函数</li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">权限:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">permissions</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#ffffff">{</span>
<span style="color:#87ceeb">// ...</span>
<span style="color:#ffa0a0">"permissions"</span><span style="color:#ffffff">:{</span>
<span style="color:#87ceeb">// ...</span>
<span style="color:#ffa0a0">"Push"</span><span style="color:#ffffff">:</span> <span style="color:#ffffff">{</span>
<span style="color:#ffa0a0">"description"</span><span style="color:#ffffff">:</span> <span style="color:#ffa0a0">"消息推送"</span>
<span style="color:#ffffff">}</span>
<span style="color:#ffffff">}</span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<p><span style="color:#474747;"><span style="background-color:#f6f4f2;">属性:</span></span></p>
<ul><li>cover: 设定显示推送消息的模式 <p style="margin-left:0;"><span style="color:#474747;">可取值true或false,true表示推送消息覆盖模式显示,即仅显示最后接收到的推送消息;false表示在系统消息中心显示多条消息。 默认值为ture。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.2+ (支持)</li><li>iOS - 4.3+ (不支持) : <p style="margin-left:0;"><span style="color:#474747;">不支持覆盖消息,每条信息都在系统消息中心,忽略cover属性值。</span></p> </li></ul></li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_15-->addEventListener</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">添加推送消息事件监听器</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span> <span style="color:#f0e68c"><strong>event</strong></span><span style="color:#ffffff">,</span><span style="color:#ffffff"> listener</span><span style="color:#ffffff">,</span> <span style="color:#98fb98">Boolean</span> <span style="color:#ffffff">);</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">添加推送消息事件监听器,当指定推送事件发出时触发。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>type: <em>( String ) 必选 </em>事件类型 <p style="margin-left:0;"><span style="color:#474747;">支持事件类型:"click"-从系统消息中心点击消息启动应用事件;"receive"-应用从推送服务器接收到推送消息事件。</span></p> </li><li>listener: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.PushReceiveCallback">PushReceiveCallback</a> ) 必选 </em>事件监听器回调函数,在接收到推送消息时调用 <p style="margin-left:0;"></p> </li><li>capture: <em>( Boolean ) 可选 </em>是否捕获事件,此处可忽略 <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持:</span></strong></span></h2>
<ul><li>Android - 2.2+ (支持)</li><li>iOS - 4.3+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">在客户端在运行时收到推送消息触发receive事件,离线接收到的推送消息全部进入系统消息中心。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例:</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
<span style="color:#f0e68c"><strong><head></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"initial-scale=1.0, maximum-scale=1.0, user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Push Example</span><span style="color:#f0e68c"><strong></title></strong></span>
<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// 监听plusready事件</span><span style="color:#ffffff">
document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'plusready'</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span>
<span style="color:#87ceeb">// 扩展API加载完毕,现在可以正常调用扩展API</span>
<span style="color:#87ceeb">// 添加监听从系统消息中心点击某条消息启动应用事件</span><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'click'</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">msg</span><span style="color:#ffffff">){</span>
<span style="color:#87ceeb">// 分析msg.payload处理业务逻辑 </span><span style="color:#ffffff">
alert</span><span style="color:#ffffff">(</span> <span style="color:#ffa0a0">'You clicked: '</span> <span style="color:#ffffff">+</span><span style="color:#ffffff"> msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">content </span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>false</strong></span> <span style="color:#ffffff">);</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#f0e68c"><strong></script></strong></span>
<span style="color:#f0e68c"><strong></head></strong></span>
<span style="color:#f0e68c"><strong><body></strong></span>
<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
</code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_18-->clear</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">清空所有推送消息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">clear</span><span style="color:#ffffff">();</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">清空系统消息中心所有的推送消息。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_19-->createMessage</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">创建本地消息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">createMessage</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> content</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> payload</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> option </span><span style="color:#ffffff">);</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">在本地直接创建推送消息,并添加到系统消息中心。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>content: <em>( String ) 必选</em> <p style="margin-left:0;"><span style="color:#474747;">消息显示的内容,在系统通知中心中显示的文本内容。</span></p> </li><li>payload: <em>( String ) 可选</em> <p style="margin-left:0;"><span style="color:#474747;">消息承载的数据,可根据业务逻辑自定义数据格式。</span></p> </li><li>options: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.MessageOptions">MessageOptions</a> ) 可选</em> <p style="margin-left:0;"><span style="color:#474747;">创建消息的额外参数,参考MessageOptions。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_21-->getAllMessage</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取所有推送消息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#98fb98">PushMessage</span><span style="color:#ffffff">[]</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getAllMessage</span><span style="color:#ffffff">();</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取客户端接收到的所有推送消息。 仅包括在系统消息中心显示的推送消息,不包括调用setAutoNotification(false)方法设置不显示推送消息后接收到的消息。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p><ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.PushMessage">PushMessage</a><span style="color:#474747;"><span style="background-color:#f6f4f2;"> : Array对象,推送消息PushMessage数组。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持:</span></strong></span></h2>
<ul><li>Android - 2.2+ (支持)</li><li>iOS - 4.3+ (不支持) : <p style="margin-left:0;"><span style="color:#474747;">无法获取系统消息中心的消息列表,调用此方法返回空数组。</span></p> </li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_23-->getClientInfo</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">获取客户端推送标识信息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#98fb98">ClientInfo</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getClientInfo</span><span style="color:#ffffff">();</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">客户端标识信息用于业务服务器下发推送消息时提交给推送服务器的数据,用于说明下发推送消息的接收者(客户端)。 通常需要客户端在第一次运行时获取并提交到业务服务器绑定。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p><ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.ClientInfo">ClientInfo</a><span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 客户端推送标识信息对象</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例:</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
<span style="color:#f0e68c"><strong><head></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"initial-scale=1.0, maximum-scale=1.0, user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Push Example</span><span style="color:#f0e68c"><strong></title></strong></span>
<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// 监听plusready事件</span><span style="color:#ffffff">
document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(‘</span><span style="color:#ffffff">plusready</span><span style="color:#ffffff">’,</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span>
<span style="color:#87ceeb">// 扩展API加载完毕,现在可以正常调用扩展API</span>
<span style="color:#87ceeb">// 获取客户端标识信息</span>
<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> info </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getClientInfo</span><span style="color:#ffffff">();</span><span style="color:#ffffff">
alert</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> JSON</span><span style="color:#ffffff">.</span><span style="color:#ffffff">stringify</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> info </span><span style="color:#ffffff">)</span> <span style="color:#ffffff">);</span>
<span style="color:#87ceeb">// 添加监听从系统消息中心点击消息启动事件</span><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(‘</span><span style="color:#ffffff">click</span><span style="color:#ffffff">’,</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">msg</span><span style="color:#ffffff">){</span>
<span style="color:#87ceeb">// 分析msg.payload处理业务逻辑 </span><span style="color:#ffffff">
alert</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'You clicked: '</span> <span style="color:#ffffff">+</span><span style="color:#ffffff"> msg</span><span style="color:#ffffff">.</span><span style="color:#ffffff">content</span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>false</strong></span><span style="color:#ffffff">);</span>
<span style="color:#f0e68c"><strong></script></strong></span>
<span style="color:#f0e68c"><strong></head></strong></span>
<span style="color:#f0e68c"><strong><body></strong></span>
<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
</code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_26-->getClientInfoAsync</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">异步获取客户端推送标识信息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getClientInfoAsync</span><span style="color:#ffffff">(</span><span style="color:#ffffff">successCB</span><span style="color:#ffffff">,</span><span style="color:#ffffff"> errorCB</span><span style="color:#ffffff">);</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">HBuilderX2.5.11+版本新增。 用于解决plus.push.getClientInfo同步获取可能返回数据为空的问题。 客户端标识信息用于业务服务器下发推送消息时提交给推送服务器的数据,用于说明下发推送消息的接收者(客户端)。 通常需要客户端在第一次运行时获取并提交到业务服务器绑定。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>successCB: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.ClientInfoSuccessCallback">ClientInfoSuccessCallback</a> ) 必选 </em>获取客户端推送标识信息成功回调 <p style="margin-left:0;"><span style="color:#474747;">成功获取客户端推送标识信息时触发。</span></p> </li><li>errorCB: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.ClientInfoErrorCallback">ClientInfoErrorCallback</a> ) 必选 </em>获取客户端推送标识信息失败回调 <p style="margin-left:0;"><span style="color:#474747;">获取客户端推送标识信息发生错误时触发。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例:</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff"> getPushInfo</span><span style="color:#ffffff">(){</span><span style="color:#ffffff">
console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">"异步获取客户端推送标识信息"</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">getClientInfoAsync</span><span style="color:#ffffff">(</span><span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">info</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'Success'</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffffff">JSON</span><span style="color:#ffffff">.</span><span style="color:#ffffff">stringify</span><span style="color:#ffffff">(</span><span style="color:#ffffff">info</span><span style="color:#ffffff">));</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">){</span><span style="color:#ffffff">
console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffa0a0">'Failed'</span><span style="color:#ffffff">);</span><span style="color:#ffffff">
console</span><span style="color:#ffffff">.</span><span style="color:#ffffff">log</span><span style="color:#ffffff">(</span><span style="color:#ffffff">JSON</span><span style="color:#ffffff">.</span><span style="color:#ffffff">stringify</span><span style="color:#ffffff">(</span><span style="color:#ffffff">e</span><span style="color:#ffffff">));</span>
<span style="color:#ffffff">})</span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_30-->setAutoNotification</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">设置程序是否将消息显示在系统消息中心</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">setAutoNotification</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> notify </span><span style="color:#ffffff">);</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">默认情况下程序在接收到推送消息后将会在系统消息中心显示,通过此方法可关闭默认行为,接收到推送消息后不在系统消息中心显示,通过addEventListener方法的“receive”事件监听处理接收到的消息。 在这种模式下可通过createMessage方法创建在系统消息中心显示的消息。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>notify: <em>( Boolean ) 必选 </em>是否自动提示推送消息 <p style="margin-left:0;"><span style="color:#474747;">可取值true或false,true表示自动显示推送消息,false则不显示。默认值为true。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持:</span></strong></span></h2>
<ul><li>Android - 2.2+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">如果程序没有运行时接收到推送消息,则在程序启动后调用addEventListener方法监听“receive”事件时返回接收到的消息。 注意:个推平台仅透传消息才支持此功能,其它消息依然会显示到系统消息中心。</span></p> </li><li>iOS - 4.3+ (不支持) : <p style="margin-left:0;"><span style="color:#474747;">无法修改是否显示离线推送消息,当程序在前台运行时接收到消息时一定不会添加到系统消息中心,当程序在不再前台运行时一定会添加到系统消息中。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">示例:</span></strong></span></h2>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#cccccc"><!DOCTYPE html></span>
<span style="color:#f0e68c"><strong><html></strong></span>
<span style="color:#f0e68c"><strong><head></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>charset</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"utf-8"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><meta</strong></span> <span style="color:#bdb76b"><strong>name</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"viewport"</span> <span style="color:#bdb76b"><strong>content</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"initial-scale=1.0, maximum-scale=1.0, user-scalable=no"</span><span style="color:#f0e68c"><strong>/></strong></span>
<span style="color:#f0e68c"><strong><title></strong></span><span style="color:#ffffff">Push Example</span><span style="color:#f0e68c"><strong></title></strong></span>
<span style="color:#f0e68c"><strong><script</strong></span> <span style="color:#bdb76b"><strong>type</strong></span><span style="color:#ffffff">=</span><span style="color:#ffa0a0">"text/javascript"</span><span style="color:#f0e68c"><strong>></strong></span>
<span style="color:#87ceeb">// 监听plusready事件</span><span style="color:#ffffff">
document</span><span style="color:#ffffff">.</span><span style="color:#ffffff">addEventListener</span><span style="color:#ffffff">(</span> <span style="color:#ffa0a0">"plusready"</span><span style="color:#ffffff">,</span> <span style="color:#f0e68c"><strong>function</strong></span><span style="color:#ffffff">(){</span>
<span style="color:#87ceeb">// 扩展API加载完毕,现在可以正常调用扩展API</span>
<span style="color:#87ceeb">// 在程序运行时接收到的消息不显示在系统消息中心</span><span style="color:#ffffff">
plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">setAutoNotification</span><span style="color:#ffffff">(</span> <span style="color:#f0e68c"><strong>false</strong></span> <span style="color:#ffffff">);</span>
<span style="color:#ffffff">},</span> <span style="color:#f0e68c"><strong>false</strong></span> <span style="color:#ffffff">);</span>
<span style="color:#f0e68c"><strong></script></strong></span>
<span style="color:#f0e68c"><strong></head></strong></span>
<span style="color:#f0e68c"><strong><body></strong></span>
<span style="color:#f0e68c"><strong></body></strong></span>
<span style="color:#f0e68c"><strong></html></strong></span>
</code></span></span></code></pre>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><ahref="https://uniapp.dcloud.io/use-html5plus">uni-app使用plus注意事项</a></span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_32-->remove</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">删除推送消息</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> plus</span><span style="color:#ffffff">.</span><span style="color:#ffffff">push</span><span style="color:#ffffff">.</span><span style="color:#ffffff">remove</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> message </span><span style="color:#ffffff">)</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">删除系统消息中心指定的推送消息,可通过getAllMessage方法获取所有的消息后进行操作。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>message: <em>( <ahref="https://blog.csdn.net/qq_40575646/article/details/122837221#plus.push.PushMessage">PushMessage</a> ) 必选 </em>要删除的消息对象,可通过getAllMessage()方法来获取消息。 <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">平台支持:</span></strong></span></h2>
<ul><li>Android - 2.2+ (支持)</li><li>iOS - 4.3+ (不支持) : <p style="margin-left:0;"><span style="color:#474747;">无法对单条消息进行删除操作,可调用clear()方法清空所有消息。</span></p> </li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_34-->ClientInfo</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">JSON对象,获取的客户端标识信息</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">属性:</span></strong></span></h2>
<ul><li>id: <em>(String 类型 )</em>推送通道标识 <p style="margin-left:0;"><span style="color:#474747;">目前支持以下推送通道: "igexin" - 表示个推推送; "mipush" - 表示小米推送; "unipush" - 表示DCloud UniPush。</span></p> </li><li>token: <em>(String 类型 )</em>设备令牌(iOS设备唯一标识),用于APNS服务推送中标识设备的身份 <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.2+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">设备的唯一标识号,通常与clientid值一致。</span></p> </li><li>iOS - 4.5+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">设备的DeviceToken值,向APNS服务器发送推送消息时使用。</span></p> </li></ul></li><li>clientid: <em>(String 类型 )</em>推送服务令牌(设备唯一标识),用于标识推送信息接收者身份 <p style="margin-left:0;"><span style="color:#474747;">第三方推送服务器管理的设备唯一标识,在iOS平台此值通常与token不同;在其它平台此值通常与token值一致。 此值与设备及应用都相关,即不同的apk/ipa安装到同一台设备上的值都不相同。</span></p> </li><li>appid: <em>(String 类型 )</em>第三方推送服务的应用标识 <p style="margin-left:0;"><span style="color:#474747;">第三方推送服务器管理的应用标识,通常需要在第三方推送服务器平台进行注册获取。</span></p> </li><li>appkey: <em>(String 类型 )</em>第三方推送服务器的应用键值 <p style="margin-left:0;"><span style="color:#474747;">第三方推送服务器管理的应用键值,通常需要在第三方推送服务器平台进行注册获取。</span></p> </li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_35-->PushMessage</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">JSON对象,推送消息对象</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">属性:</span></strong></span></h2>
<ul><li>title: <em>(String 类型 )</em>推送消息显示的标题 <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.2+ (支持)</li><li>iOS - ALL (支持) : <p style="margin-left:0;"><span style="color:#474747;">。</span></p> </li></ul></li><li>content: <em>(String 类型 )</em>推送消息显示的内容</li><li>payload: <em>(JSON 类型 )</em>推送消息承载的数据 <p style="margin-left:0;"><span style="color:#474747;">如果推送消息中传输的数据不符合JSON格式,则作为String类型数据保存。</span></p> </li><li>aps: <em>(JSON 类型 )</em>Apple APNS推送协议数据 <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.2+ (不支持) : <p style="margin-left:0;"><span style="color:#474747;">不支持此数据,返回值为undefined。</span></p> </li><li>iOS - 5.0+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">仅封装标准APNS协议中的数据,其它数据封装在payload中。如果是通过本地API创建的消息此属性值则为undefined。</span></p> </li></ul></li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_36-->MessageOptions</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">JSON对象,获客户端创建本地消息的参数</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">属性:</span></strong></span></h2>
<ul><li>appid: <em>(String 类型 )</em>要启动流应用的appid <p style="margin-left:0;"><span style="color:#474747;">仅在流应用环境中有效,默认值为当前流应用的appid。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - ALL (不支持)</li><li>iOS - ALL (不支持)</li></ul></li><li>cover: <em>(Boolean 类型 )</em>是否覆盖上一次提示的消息 <p style="margin-left:0;"><span style="color:#474747;">可取值true或false,true为覆盖,false不覆盖。 默认为false。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - ALL (支持)</li><li>iOS - 10.0+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">iOS10以下系统不支持覆盖。</span></p> </li></ul></li><li>delay: <em>(Number 类型 )</em>提示消息延迟显示的时间 <p style="margin-left:0;"><span style="color:#474747;">当设备接收到推送消息后,可不立即显示,而是延迟一段时间显示,延迟时间单位为s,默认为0s,立即显示。</span></p> </li><li>icon: <em>(String 类型 )</em>推送消息的图标 <p style="margin-left:0;"><span style="color:#474747;">本地图片地址,相对路径 - 相对于当前页面的host位置,如"a.jpg",注意当前页面为网络地址则不支持; 绝对路径 - 系统绝对路径,如Android平台"/sdcard/logo.png",此类路径通常通过其它5+ API获取的; 扩展相对路径URL(RelativeURL) - 以"_"开头的相对路径,如"_www/a.jpg"; 本地路径URL - 以“file://”开头,后面跟随系统绝对路径。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.3+ (支持)</li><li>iOS - ALL (不支持) : <p style="margin-left:0;"><span style="color:#474747;">不支持自定义图片,固定使用应用图标。</span></p> </li></ul></li><li>sound: <em>(String 类型 )</em>推送消息的提示音 <p style="margin-left:0;"><span style="color:#474747;">显示消息时的播放的提示音,可取值: “system”-表示使用系统通知提示音; “none”-表示不使用提示音; 默认值为“system”。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - 2.3+ (支持)</li><li>iOS - ALL (支持) : <p style="margin-left:0;"><span style="color:#474747;">当程序在前台运行时,提示音不生效。 注:通常应该设置延迟时间,当程序切换到后台才创建本地推送消息时生效。</span></p> </li></ul></li><li>title: <em>(String 类型 )</em>推送消息的标题 <p style="margin-left:0;"><span style="color:#474747;">在系统消息中心显示的通知消息标题,默认值为程序的名称。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - ALL (支持)</li><li>iOS - 10+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">iOS10及以上版本支持设置标题,低版本忽略此属性。</span></p> </li></ul></li><li>subtitle: <em>(String 类型 )</em>推送消息的副标题 <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - ALL (不支持)</li><li>iOS - 10+ (支持) : <p style="margin-left:0;"><span style="color:#474747;">iOS10及以上版本支持设置副标题,低版本忽略此属性。</span></p> </li></ul></li><li>when: <em>(Date 类型 )</em>消息上显示的提示时间 <p style="margin-left:0;"><span style="color:#474747;">默认为当前时间,如果延迟显示则使用延时后显示消息的时间。</span></p> <h3 style="margin-left:0;">平台支持</h3>
<ul style="margin-left:2em;"><li>Android - ALL (支持)</li><li>iOS - ALL (不支持) : <p style="margin-left:0;"><span style="color:#474747;">不支持设定消息的显示时间,由系统自动管理消息的创建时间。</span></p> </li></ul></li></ul>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_37-->PushReceiveCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">客户端接收到推送消息的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onReceive</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
<span style="color:#87ceeb">// Recieved push message code.</span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>msg: <em>( String ) 必选 </em>接收到的推送信息msg <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_38-->PushClickCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">用户点击推送消息事件的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onClick</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> msg </span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
<span style="color:#87ceeb">// Clicked push message code. </span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>msg: <em>( String ) 必选 </em>用户点击的推送信息msg <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_39-->ClientInfoSuccessCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">异步获取客户端推送标识信息成功的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onSuccess</span><span style="color:#ffffff">(</span><span style="color:#ffffff"> info </span><span style="color:#ffffff">)</span> <span style="color:#ffffff">{</span>
<span style="color:#87ceeb">// getClientInfo success. </span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">异步获取客户端推送标识信息成功时回调。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>info: <em>( <ahref="https://www.html5plus.org/doc/zh_cn/push.html#plus.push.ClientInfo">ClientInfo</a> ) 必选 </em>客户端推送标识信息 <p style="margin-left:0;"></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
<h1 style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;"><!--LINK#0_41-->ClientInfoErrorCallback</span></span></h1>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">异步获取客户端推送标识信息失败的回调函数</span></span></p>
<pre class="has" style="margin-left:0;"><code class="language-prettyprint"><span style="background-color:#333333"><span style="color:#474747"><code>
<span style="color:#f0e68c"><strong>void</strong></span><span style="color:#ffffff"> onError</span><span style="color:#ffffff">(</span><span style="color:#ffffff">error</span><span style="color:#ffffff">){</span>
<span style="color:#87ceeb">// Handle the error</span>
<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> code </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> error</span><span style="color:#ffffff">.</span><span style="color:#ffffff">code</span><span style="color:#ffffff">;</span> <span style="color:#87ceeb">// 错误编码</span>
<span style="color:#f0e68c"><strong>var</strong></span><span style="color:#ffffff"> message </span><span style="color:#ffffff">=</span><span style="color:#ffffff"> error</span><span style="color:#ffffff">.</span><span style="color:#ffffff">message</span><span style="color:#ffffff">;</span> <span style="color:#87ceeb">// 错误描述信息</span>
<span style="color:#ffffff">}</span>
</code></span></span></code></pre>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">说明:</span></strong></span></h2>
<p style="margin-left:0;"><span style="color:#474747;"><span style="background-color:#f6f4f2;">异步获取推送标识信息失败时触发。</span></span></p>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">参数:</span></strong></span></h2>
<ul><li>error: <em>( Exception ) 可选 </em>错误信息 <p style="margin-left:0;"><span style="color:#474747;">可通过error.code(Number类型)获取错误编码; 可通过error.message(String类型)获取错误描述信息。</span></p> </li></ul>
<h2 style="margin-left:.8em;"><span style="color:#f13a0e;"><strong><span style="background-color:#f6f4f2;">返回值:</span></strong></span></h2>
<p>void<span style="color:#474747;"><span style="background-color:#f6f4f2;"> : 无</span></span></p>
</div>
</div>
<div id="treeSkill"></div>
页:
[1]