帮助与文档

> >
윈도우 10 알약 다운로드
  • 通用集成步骤
    • 下载MobPush For JS组件

打开Github下载MobPush-For-JavaScript项目。将JSApi/PushSDK.js拷贝到Web页面可以访问的路径(现在不支持浏览器打开的web应用,只支持App内置的Web页面,这个web页可以自己在本地页就是项目里创建html文件,这个html文件也可以网上得到)。

  • 导入js脚本

在Web页中加入PushSDK.js脚本。如:

<script language="javascript" type="text/javascript" src="PushSDK.js"></script>
  • 集成android原生桥接

把MobPush-For-JavaScript项目中AndroidDemo里com/mob/js文件夹下的文件(除demo文件夹外)拷贝到项目中,在工程的build.gradle中配置:

buildscript {
    repositories {
        maven {
            url 'http://mvn.mob.com/android'
        }
    }
    dependencies {
        classpath 'com.mob.sdk:MobSDK:+'
    }
}

 

在App的build.gradle中配置:

apply plugin: 'com.mob.sdk'
MobSDK {
    appKey "您的appkey"
    appSecret "您的appSecret"

    MobGUI(true)
    MobPush {
        devInfo {
            HUAWEI{
                appId "xxx"
            }

            MEIZU{
                appId "xxx"
                appKey "xxx"
            }

            XIAOMI{
                appId "xxx"
                appKey "xxx"
            }
        }
    }
}

相关API

  1. 初始化SDK
$pushsdk.initMobPushJS($pushsdk.PushEnvironment.Release);
  • 发送应用内自定义消息
var params = {
    "msgType" : $pushsdk.SendMsgType.socket,
    "content" : "收到应用内消息",
    "space"   : 0,
    "isProductionEnvironment" : $pushsdk.PushEnvironment.Debug,
   };
$pushsdk.sendCustomMsg(params, function (reqID, content ,messageId) {});

发送通知

var params = {
    "msgType" : $pushsdk.SendMsgType.apns,
    "content" : "收到APNs推送",
    "timedSpace"   : 0,
    "isProductionEnvironment" : $pushsdk.PushEnvironment.Debug,
};
$pushsdk.sendAPNsMsg(params, function (reqID, body , mobpushMessageId) {});
  • 发送定时通知
var params = {
    "msgType" : $pushsdk.SendMsgType.timed,
    "content" : "一分钟后收到APNs推送",
    "timedSpace"   : 1,
    "isProductionEnvironment" : $pushsdk.PushEnvironment.Debug,
    "callBackName" : "receiverCallBack",
};
$pushsdk.sendAPNsMsg(params, function (reqID, body , mobpushMessageId) {});
  • 发送本地通知
var params = {
    "msgType" : $pushsdk.SendMsgType.local,
    "content" : "收到本地通知",
    "title"   : "测试-我是标题",
    "timedSpace"   : 1,
};
 $pushsdk.sendLocalNotify(params, function (reqID, body, title) {});
  • 设置别名
var params = {
   "alias" : "测试的别名",
   };
$pushsdk.setAlias(params,function(seqId, alias, operation, errorCode){});
  • 获取别名
$pushsdk.getAlias(function(seqId, operation, errorCode){});
  • 删除别名
$pushsdk.deleteAlias(function(seqId, operation, errorCode){});

  • 添加标签
$pushsdk.addTags(params, function(seqId, tags, operation, errorCode){});
  • 获取标签
$pushsdk.getTags(function(seqId, tags, operation, errorCode){});
  • 删除标签
var params = {
    "tags" : ['测试tag1','测试tag2']
    };
$pushsdk.deleteTags(params, function(seqId, tags, operation, errorCode){})
  • 清除所有标签
$pushsdk.cleanAllTags(function(seqId, tags, operation, errorCode){});

 

 

 

 

接收推送监听回调
在MobPush.js中定义了onMessageCallBack方法进行接收推送监听回调,分别能接收透传、通知、点击打开通知、操作tags和操作alias等操作的监听回调,此方法是通过原生在接收到推送操作回调后主动去回调给js的。

/**
* 添加MobPush推送接收监听
* @param body
* body: {"action":0,"result":{}}
*/
this.onMessageCallBack = function(body){
alert(body.action==0?"接收到透传信息"
:(body.action ==1?"接收到通知"
:(body.action == 2?"接收到通知点击打开"
:(body.action == 3?"接收到标签操作"
:"接收到别名操作"))));
if(body.action ==0){
//接收到透传信息回调
}
}

回调数据body格式:{"action":0,"result":{}}
action的取值:0(透传),1(通知),2(点击打开通知),3(tags),4(alias)
action为0:
result :{"messageId":"","content":"","extrasMap":{},"timestamp":""}
action为1:
result :{"messageId":"","content":"","title":"","style":"","styleContent":"", "extrasMap":{},"timestamp":"","inboxStyleContent":"","channel":""}
action为2:
result :{"messageId":"","content":"","title":"","style":"","styleContent":"","extrasMap":{},"timestamp":"","inboxStyleContent":"","channel":""}
action为3:
result :{"tags":"","operation":"","errorCode":""}
而 operation 操作说明(0 获取, 1 设置, 2 删除,3 清空)而errorCode 操作结果(0 成功,其他失败,见{@link MobPushErrorCode})
action为4:
result :{"alias":"","operation":"","errorCode":""}
而operation 操作说明(0 获取, 1 设置, 2 删除),errorCode 操作结果(0 成功,其他失败,见{@link MobPushErrorCode})

 

xlsm 다운로드 새 소리 다운로드 삼성 마켓 다운로드

相关文档