aliPush模块封装了阿里移动推送sdk,阿里移动推送(Alibaba Cloud Mobile Push)是基于大数据的移动智能推送服务,帮助App快速集成移动推送的功能,在实现高效、精确、实时的移动推送的同时,极大地降低了开发成本。让开发者最有效地与用户保持连接,从而提高用户活跃度、提高应用的留存率。 开发者在使用aliPush模块时,需要开发者自行到阿里云注册账号,并开通移动推送功能。本模块与其它阿里相关或者集成了小米推送相关模块会存在冲突的可能,请大家使用时注意。
点击进入模块详情
- <!DOCTYPE html>
- <html>
- <head>
- <title>Module Develop</title>
- <meta charset="utf-8">
- <meta name="viewport"
- content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <style type="text/css">
- html,
- body {
- height: 100%
- }
- body {
- background-color: #fff;
- margin: 0;
- }
- #wrap {
- height: 100%;
- position: relative;
- }
- #header {
- padding-top: 20px;
- background-color: #5082c2;
- height: 44px;
- position: relative;
- }
- #header h1 {
- font-size: 20px;
- height: 44px;
- line-height: 44px;
- margin: 0em;
- color: #fff;
- margin-left: 100px;
- margin-right: 100px;
- text-align: center;
- }
- #main {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- }
- a.button {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- -webkit-box-align: center;
- height: 32px;
- margin: 8px;
- background-color: rgba(240, 240, 240, 1.0);
- border-color: rgba(220, 220, 220, 1.0);
- border-width: 2px;
- border-style: solid;
- }
- a.active {
- background-color: rgba(240, 240, 240, 0.7);
- }
- </style>
- </head>
- <body>
- <div id="wrap">
- <div id="main">
- <a class="button" tapmode="active" onclick="registerPush()">阿里推送注册</a>
- <a class="button" tapmode="active" onclick="setAutoRegister()">设置是否在app启动是自动注册推送</a>
- <a class="button" tapmode="active" onclick="getAutoRegister()">获取是否在app启动是自动注册推送</a>
- <a class="button" tapmode="active" onclick="isRegister()">是否注册成功</a>
- <a class="button" tapmode="active" onclick="getDeviceId()">获取设备ID</a>
- <a class="button" tapmode="active" onclick="onAppStart()">启动app统计(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="addTag()">添加标签</a>
- <a class="button" tapmode="active" onclick="removeTag()">删除标签</a>
- <a class="button" tapmode="active" onclick="listTags()">查询标签</a>
- <a class="button" tapmode="active" onclick="addAlias()">添加别名</a>
- <a class="button" tapmode="active" onclick="removeAlias()">删除别名</a>
- <a class="button" tapmode="active" onclick="listAliases()">查询别名</a>
- <a class="button" tapmode="active" onclick="bindAccount()">绑定账号</a>
- <a class="button" tapmode="active" onclick="unbindAccount()">解除绑定</a>
- <a class="button" tapmode="active" onclick="setDoNotDisturb()">设置免打扰时间段(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="closeDoNotDisturbMode()">取消免打扰(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="clearNotifications()">删除所有通知(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="bindPhoneNumber()">绑定电话号码(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="unbindPhoneNumber()">解绑电话号码(仅安卓有效)</a>
- <a class="button" tapmode="active" onclick="setNotificationSoundFilePath()">设置推送通知声音(仅安卓有效)</a>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- var aliPush = null;
- apiready = function () {
- aliPush = api.require('aliPush');
- if (!aliPush) {
- alert("请添加模块后编译");
- return;
- }
- //isRegister();
- aliPush.addEventListener({
- name: 'onMessage'
- }, function (ret, err) {
- alert("onMessage>>>addEventListener>>>>" + JSON.stringify(ret));
- });
- aliPush.addEventListener({
- name: 'onNotification'
- }, function (ret, err) {
- alert("onNotification>>>addEventListener>>>>" + JSON.stringify(ret));
- });
- aliPush.addEventListener({
- name: 'onNotificationOpened'
- }, function (ret, err) {
- alert("onNotificationOpened>>>addEventListener>>>>" + JSON.stringify(ret));
- });
- aliPush.addEventListener({
- name: 'onNotificationRemoved'
- }, function (ret, err) {
- alert("onNotificationRemoved>>>addEventListener>>>>" + JSON.stringify(ret));
- });
- api.addEventListener({
- name: 'noticeclicked'
- }, function (ret, err) {
- alert("noticeclicked>>>" + JSON.stringify(ret.value));
- });
- // var fs = api.require('fs');
- // var ret = fs.copyToSync({
- // oldPath: 'widget://res/alicloud_notification_sound.mp3',
- // newPath: 'fs://'
- // });
- // if (ret.status) {
- // alert('拷贝成功!');
- // setNotificationSoundFilePath();
- // } else {
- // alert('拷贝失败!');
- // }
- //setAdvCusNotif();
- }
- function registerPush() {
- aliPush.registerPush(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- //getDeviceId();
- });
- }
- function setAutoRegister() {
- var ret = aliPush.setAutoRegister({ isAutoRegister: true });
- alert(JSON.stringify(ret));
- }
- function getAutoRegister() {
- var ret = aliPush.getAutoRegister();
- alert(JSON.stringify(ret));
- }
- function getDeviceId() {
- aliPush.getDeviceId(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- console.log(JSON.stringify(ret));
- });
- }
- function isRegister() {
- aliPush.isRegister(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- //getDeviceId();
- });
- }
- function onAppStart() {
- aliPush.onAppStart(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function addTag() {
- aliPush.addTag({
- target: 3,
- tag: "apicloud1 apicloud2",
- alias: 'aliasname'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function removeTag() {
- aliPush.removeTag({
- target: 3,
- tag: "apicloud1 apicloud2",
- alias: 'aliasname'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function listTags() {
- aliPush.listTags(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function addAlias() {
- aliPush.addAlias({
- alias: 'test01'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function removeAlias() {
- aliPush.removeAlias({
- alias: 'test01'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function listAliases() {
- aliPush.listAliases(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function bindAccount() {
- aliPush.bindAccount({
- account: "apicloudaccount"
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function unbindAccount() {
- aliPush.unbindAccount(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function setDoNotDisturb() {
- aliPush.setDoNotDisturb({
- startHour: 23,
- startMinute: 0,
- endHour: 8,
- endMinute: 0
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function closeDoNotDisturbMode() {
- aliPush.closeDoNotDisturbMode(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function clearNotifications() {
- aliPush.clearNotifications(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function bindPhoneNumber() {
- aliPush.bindPhoneNumber({
- phoneNumber: "1300000000"
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function unbindPhoneNumber() {
- aliPush.unbindPhoneNumber(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function setNotificationSoundFilePath() {
- aliPush.setNotificationSoundFilePath({
- filePath: "fs://alicloud_notification_sound.mp3"
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function turnOnPushChannel() {
- aliPush.turnOnPushChannel(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function turnOffPushChannel() {
- aliPush.turnOffPushChannel(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function checkPushChannelStatus() {
- aliPush.checkPushChannelStatus(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function setAdvCusNotif() {
- aliPush.setAdvCusNotif({
- remindType: 2, //0:静默 1:震动 2:声音 3:声音+震动
- notificationId: 2,//默认2 范围:1-100
- serverOptionFirst: false,
- appInForeground: true //设置当推送到达时如果应用处于前台不创建通知: true : 创建 | false: 不创建
- }, function (ret, err) {
- setNotificationSoundFilePath();
- alert(JSON.stringify(ret));
- });
- }
- </script>
- </html>
复制代码
|