supersdk

文档中心

文档中心

下载文档

MobPush


The push system is designed to provide a unified push service solution for the game. Recommended to use.

##Preparation before integration 1. Download resources, please contact SDK colleagues

  1. Import the resource and import mobpush.unitypackage into the game project.

  2. For third-party parameter application, please confirm which third-party push channel will be integrated. Currently, Google Push, Huawei Push, Xiaomi Push, etc. are supported. Game developer can select one to integrate based on actual needs, and provide corresponding third party parameters to the SuperSDK colleagues.

  3. Invoke the push interface to integrate the corresponding SuperSDK remote push interface. If you need to integrate the local push, you can do it according to the following local push files.

#Interface must be integrated:

Register Push Service (required)

Interface description: Register the push service, invoke after the initialization is completed, android will not receive the callback without registering the push.

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
SuperSDK.getInstance().Invoke("mobpushsdk", "registerPush", paramsDic);

Bind user (required)

Interface description: Bind push user, invoked after login is completed.

Note: The incoming user ID must be the osdk_user_id obtained by SuperSDK;

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
paramsDic.Add("osdk_user_id", osdkUserId); //必传,用户ID,必须是带前缀的用户ID,如000016_123456
SuperSDK.getInstance().Invoke("mobpushsdk", "bindUser", paramsDic);

Remote notification

Remote notification provides the function of server push

Receive the message pushed by the server (optional)

Interface description: When the game developer invokes the registration push service and binds two user interfaces, it can receive the message pushed by the server. The unified callback of SuperSDK receives it, as shown below; Note: The android third-party push may not receive the third-party push callback because the manufacturer and the mobile phone.

Interface callback:

public void OnCallBack(string moduleName, string funcName, string result)
{
    Debug.Log("moduleName:" + moduleName);
    Debug.Log("funcName:" + funcName);
    Debug.Log("result:" + result);
    if (moduleName.Equals("mobpushsdk"))
    {
        if (funcName.Equals("receiveRemoteNotification"))
        {
            Receive(result);
        }
    }
}
//这个方法处理服务端推送消息
privite void Receive(String result) {
    //推送的消息放在data里面,为json格式的字符串
    Debug.Log("收到远程推送消息:" + result);
}

****** Receive callback moduleName : push, funcName : receiveRemoteNotification, IOS and android remote push callback are slightly different due to channel reasons. IOS:

funcName : receiveRemoteNotification,
 result : {
    "msg":"远程通知",
    "data":{
        "currentServerTimestamp":0,
        "content":"",
        "messageID":"",
        "identifier":"",
        "extraInfomation":{

        },
        "msgInfo":{
            "aps":{
                "badge":1,
                "alert":{
                    "title":"推送测试",
                    "body":"这是一条推送测试消息,点击此通知打开链接http://www.supersdk.cn"
                },
                "sound":"default"
            },
            "workId":"5ceb9d4277ee5d5c60683e84",
            "url":"http://www.supersdk.cn",  // 注意:此参数在MobPush后台设置才会存在!若不使用此功能可忽略。
            "mobpushMessageId":"296317053718368256"
        },
        "isInstantMessage":false,
        "messageType":3,
        "taskDate":0
    },
    "code":1
}

Android:

result: {
	"code": 0,
	"data": {
		"code": 0,
		"content": "test内容",//内容
		"extrasMap": {
			"workId": "5d4852fe7fbebe9a75c85ede"
		},
		"light": true,
		"messageId": "321800954716188672",
		"shake": true,
		"style": 0,//接收到推送类型
		"timestamp": 1565020926714,//时间戳
		"title": "testa",//标题
		"voice": true
	},
	"msg": "receiveRemoteNotification"
}

Local notification

The push module provides local notification function

Add local notification (important)

Interface Description: When the game needs to integrate local notification, invoke the interface that stores the local notification, as shown below:

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
// 本地推送的唯一标识符
paramsDic.Add("identifier", "1");
// 通知栏显示的推送标题
paramsDic.Add("alertTitle", "通知栏显示的推送标题");
// 通知栏显示的副标题 android无此项
paramsDic.Add("subTitle", "通知栏显示的副标题");
// 通知栏显示的推送内容
paramsDic.Add("alertBody", "通知栏显示的推送内容");
//ios:
//音频文件名称,后缀名必须是caf,且音频时长在30s以内,需将音频文件添加到工程中
//如:sound.caf
paramsDic.Add("soundName", "");

// 推送触发时间,为时间戳,单位为秒
paramsDic.Add("fireDate", System.currentTimeMillis()+"");
// 应用上显示的消息条数,仅限ios
paramsDic.Add("badge", 1);
//  1或者不传为响铃震动提示,0为不提示(可选) 仅限android
paramsDic.Add("isAlarm", 1);


SuperSDK.getInstance().Invoke("mobpushsdk", "addLocalNotifcation", paramsDic);

Interface callback:

public void OnCallBack(string moduleName, string funcName, string result)
{
    Debug.Log("moduleName:" + moduleName);
    Debug.Log("funcName:" + funcName);
    Debug.Log("result:" + result);

   if (moduleName.Equals("mobpushsdk"))
   {
        if (funcName.Equals("addLocalNotifcation"))
        {
            JsonData myData = JsonMapper.ToObject(result);
            int code = (int)myData["code"];
            if(code == SuperSDKConstants.SUCCESS){
                //添加本地推送成功
            }else if(code == -2){
                //本地已存在该identifier的任务,请根据id调用删除本地接口后,再添加
            }else{
                //本地推送添加失败,原因为:"+ myData["msg"].ToString();
            }
          
            JsonData data = JsonMapper.ToObject((JsonMapper.ToJson(myData["data"]));
            //推送的消息放在data里面,为json格式的字符串
        }
    }
}

Log printing:

moduleName : push,
funcName : addLocalNotifcation,
result : {
  "msg" : "本地推送添加成功",
  "data" : {
    "repeat" : 0,
    "alertTitle" : "通知栏显示的推送标题",
    "isSound":1,
    "alertBody" : "通知栏显示的推送内容",
    "identifier" : 1,
    "fireDate" : 1513652820000,
    "userInfo" : {
      "key" : "value"
    }
  },
  "code" : 1
}

Delete local notification for the specified identifier (optional)

Interface Description: Delete local notification based on id as follows:

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
//本地推送的唯一标识符,根据这个参数来删除
paramsDic.Add("identifier", "1");
SuperSDK.getInstance().Invoke("mobpushsdk", "deleteLocalNotification", paramsDic);

Interface callback: none

Delete all local notifications(optional)

Interface Description: Delete all existing local notificationes as follows:

Interface invoke:

SuperSDK.getInstance().Invoke("mobpushsdk", "deleteAllLocalNotifications", null);

Interface callback: none

辅助常量一览

常量字符串 实际字符串 描述
暂无 mobpushsdk 模块名称
暂无 registerPush 注册推送服务
暂无 bindUser 绑定用户
暂无 receiveRemoteNotification 接收服务端推送消息

others

##Determine if the current remote notification is off Interface invoke: if isPushStopped is true, it is closed, false means closed.

BOOL isPushStopped = SuperSDK.getInstance().InvokeBool("mobpushsdk", "isPushStopped", null);

##Start remote notification (optional) Interface invoke:

SuperSDK.getInstance().Invoke("mobpushsdk", "restartPush", null);

##Stop remote notification (optional) Interface invoke:

SuperSDK.getInstance().Invoke("mobpushsdk", "stopPush", null);

##Delete user ID/unbind user (recommended when logging out) Interface invoke:

SuperSDK.getInstance().Invoke("mobpushsdk", "deleteUser", null);