supersdk

文档中心

文档中心

下载文档

Push module


Push system is designed to provide a unified solution of push service for games

##Preparation before integration 1. Download SuperSDK4.0+ push module (Unity 3D version)

  1. Import the resources and import push.unitypackage into the libs directory of the game project.

  2. For the third-party parameter application, please confirm the third-party push channel to be integrated. Currently, Google Push, Huawei Push, and UPush access are supported, game developer can select one to integrate and provide corresponding third-party parameters(Huawei parameters documentsGoogle parameters documents、UPush does not require third-party parameters)to SuperSDK colleagues.

  3. In order to get SuperSDK push parameter, provide the push parameters of the third-party which need to be integrated, also provide the gameid, and the p12 or pem file of ios, and get the appid and appkey pushed by SuperSDK.

  4. invoke the push interface, integrate the corresponding SuperSDK remote push interface. If you need to integrate the local push, you can use the following local push documents.

Remote notification

Remote notification provides the function of server notification.

Register push

Interface description: Register the push service, invoke after the initialization is completed.

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
paramsDic.Add("lang", "en"); //海外必传,语言,可传入:zh-cn(简体中文)/zh-tw(繁体中文)/en(英文)/de(德语)/ru(俄语)/fr(法语)/es(西班牙语)/pt(葡萄牙语)/tr(土耳其语)/pl(波兰语)/ko(韩语)/ja(日语)
                      //也可通过方法获取常量:BCoreParams.Language.EN  英文
paramsDic.Add("showType","0");//显示类型,0 表示应用在前台也需要弹出通知 
//1 表示应用在前台不需要弹出通知
SuperSDK.getInstance().Invoke("push", "registerPush", paramsDic);

Bind user

Interface description: Bind push user, invoke 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("push", "bindUser", paramsDic);

Receive the message pushed by the server

Interface description: When the game invokes the register push service and binds two user interfaces, it can receive the message pushed by the server. The message is received at the unified callback of SuperSDK, as shown below;

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("push"))
    {
        if (funcName.Equals("receiveRemoteNotification"))
        {
            Receive(result);
        }
    }
}
//这个方法处理服务端推送消息
privite void Receive(String result) {
    //推送的消息放在data里面,为json格式的字符串
    Debug.Log("收到远程推送消息:" + result);
}
****** 收到回调
moduleName : push,
funcName : receiveRemoteNotification,
收到远程推送消息 : {
    "msg" : "收到远程推送",
    "data" : {
        "userInfo" : {
            "aps" : {
                "alert" : "这是一条推送测试消息!",
                "badge" : 1,
                "sound" : "default"
            }
        },
        "identifier" : "",
    },
    "code" : 1
}

Note: Server access can be integrated according to the server integration document接入

Local notification

The push module provides the function of local push.

Add local notification

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

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
// 本地推送的唯一标识符
paramsDic.Add("identifier", "1");
// 通知栏显示的推送标题
paramsDic.Add("alertTitle", "通知栏显示的推送标题");
// 通知栏显示的推送内容
paramsDic.Add("alertBody", "通知栏显示的推送内容");
//通知到达时是否需要开启声音   1开启    0关闭
paramsDic.Add("isSound", "1");
//android:
//通知声音文件名称,该文件放置在游戏包体的res/raw文件夹下,传入名称不能带有后缀
//例如res/raw/local.mp3,应该传入local
//目前安卓支持mp3和wav文件
//
//ios:
//音频文件名称,后缀名必须是caf,且音频时长在30s以内,需将音频文件添加到工程中
//如:sound.caf
paramsDic.Add("soundName", "");

Dictionary<string, object> keyDic = new Dictionary<string, object>() { };
keyDic.Add("key" , "value");
// 透传信息
paramsDic.Add("userInfo", JsonMapper.ToJson(keyDic));
// 推送触发时间,为时间戳,单位为秒
paramsDic.Add("fireDate", System.currentTimeMillis()+"");
//0 表示不重复,1表示每天重复,2表示每小时重复
paramsDic.Add("repeat", "0");
// 应用上显示的消息条数,仅限ios
paramsDic.Add("badge", 1);
//0 表示应用在前台也需要弹出通知 1 表示应用在前台不需要弹出通知
paramsDic.Add("showType", type);
//震动控制,仅限android
//0 表示不需要震动 1 表示默认震动 
//2 表示自定义震动,即震动3下,每次震动0.5秒,每次间隔0.5s
paramsDic.Add("vibrate", "1");
//icon设置,仅限android
//显示的icon名称,该文件放置在res/drawable下,并且值不带后缀
//一般不能超过521*512像素,并且背景为透明,显示时安卓会去掉RGB值,显示为灰色
paramsDic.Add("iconName", "local_icon");

SuperSDK.getInstance().Invoke("push", "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("push"))
   {
        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
}

Query local notification

Interface Description: When the game needs to integrate local notification, you need to query whether the local push of the identifier exists, as shown below:

Interface invoke:

Dictionary<string, object> paramsDic = new Dictionary<string, object>() { };
//本地推送的唯一标识符,根据这个参数来查询
paramsDic.Add("identifier", "1");
SuperSDK.getInstance().Invoke("push", "fetchLocalNotification", 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("push"))
   {
        if (funcName.Equals("fetchLocalNotification"))
        {
            JsonData myData = JsonMapper.ToObject(result);
            int code = (int)myData["code"];
            if(code == SuperSDKConstants.SUCCESS){
                JsonData data = JsonMapper.ToObject(JsonMapper.ToJson(myData["data"]));
                //该本地推送存在,推送的详细信息为data数据
            }else{
                //本地推送查询失败,原因为:"+ myData["msg"].ToString();
            }
          
           
        }
    }
}

Log printing:

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

Local notification that delete the specified identifier

Interface Description: Delete local notification based on id:

Interface invoke:

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

Interface callback: null

Delete all local notifications

Interface Description: Delete all existing local notifications as following:

Interface invoke:

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

Interface callback: null

Received a local notification message callback

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("push"))
   {
        if (funcName.Equals("receiveLocalNotification"))
        {
            //推送的消息放在data里面,为json格式的字符串
            Debug.Log("收到本地推送消息:" + result);
        }
    }
}

Log printing:

moduleName : push,
funcName : receiveLocalNotification,
result : {
  "msg" : "收到本地推送消息",
  "data" : {
    "repeat" : 0,
    "alertTitle" : "通知栏显示的推送标题",
    "isSound":1,
    "alertBody" : "通知栏显示的推送内容",
    "identifier" : 1,
    "fireDate" : 1513652820000,
    "userInfo" : {
      "key" : "value"
    }
  },
  "code" : 1
}

Appendix

Constant string **actual string ** description
None push Module name
None registerPush Register push
None bindUser Bind user
None receiveRemoteNotification Receive server notification