01/10/2025 10:53:00
Development of the Push Module
I. Plugin development
The push function can push game-related information to the player's mobile phone when the game is not running, such as various holiday activities, anniversary activities, etc.
Push methods are divided into local push and remote push
- Local push: the game generates push information by calling the local interface
- Remote push: send push information through the management console of the push channel
Push information is divided into in-app message and notification bar information
- In-app message: the information inside the app, which will not be displayed in the notification bar (iOS does not have this type)
- Notification bar information: the information which will be displayed in the notification bar
[info] Callback description of the Push module
- Each method is recommended to be called back with the unified callback processing method, and there is only one callback (adding local push notification and clearing the local push notification method cannot give any callback)
- In addition to the basic method call callbacks, the Push module needs to give push-related callbacks
- General Message Callbacks
- Push display callback, which is the callback generated when the push message is displayed, including local push and remote push
- Push click callback, which is the callback generated when the push message is clicked by the user, including local push and remote push
II. Client Plugin Development
2.1 Android Platform
2.1.1 Class implementation rules
- Package naming rule: fixed as
com.tencent.gcloud.msdk.push
- Class naming rule:
channel + Push
, such as:XGFriend
- Must implement the
PushInterface
interfaceregisterPush
function, which is used to register the channel's push function. The device can receive message push from the channel after registering the push function successfullyunregisterPush
function, which is used to unregister the channel's push function. The device can't receive message push from the channel after unregistering the push function successfullysetTag
function, which is used to set tags and can set different tags for different users, used to push different messages for different user tagsdeleteTag
function, which is used to delete tags, that is, to delete user tags that have been setaddLocalNotification
function, which is used to add local push messageclearLocalNotifications
function, which is used to clear all local push messagessetAccount
function, which is used to set the user's account to support message push by accountdeleteAccount
function, which is used to delete the account set by the user
- Must implement a
public CLASSNAME ()
constructor, which is usually used for plugin initialization
2.1.2 Description of callback fields
As for the description of the callback function, please refer to Client Plugin Development Rules
observerID
callback function IDMSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE
is used to return the call result of the push methodMSDKObserverID.MSDK_PUSH_OBSERVER_NOTIFICATION
is used to return the message results related to push message
ret
return struct must be a subclass ofMSDKRet
MSDKRet
, the basic call result class, which is the method call result return struct in the Push moduleMSDKPushRet
, the push message result class, which is the result return struct related to push messages in the Push module. In addition to the basic result parameters,InnerPushRet
also includes:type
- 0 - Remote notification received by the app is in the front end
- 1 - Remote notification received by the app in the backend
- 2 - Local notification received by the app is in the front end
- 3 - Local notification received by the app in the backend
- If not sure, please fill in -1
notification
, the content of the notification
methodNameID
Function ID defined by MSDK, used to define the callback method- Basic calling methods
MSDKMethodNameID.MSDK_PUSH_REGISTER_PUSH
is the method ID of registering the channel pushMSDKMethodNameID.MSDK_PUSH_UNREGISTER_PUSH
is the method ID of unregistering the deviceMSDKMethodNameID.MSDK_PUSH_SET_ACCOUNT
is the account setting method IDMSDKMethodNameID.MSDK_PUSH_DELETE_ACCOUNT
is the account deleting method IDMSDKMethodNameID.MSDK_PUSH_SET_TAG
is the tag setting method IDMSDKMethodNameID.MSDK_PUSH_DELETE_TAG
is the tag deleting method IDMSDKMethodNameID.MSDK_PUSH_ADD_LOCAL_NOTIFICATION
is the method ID of adding local pushMSDKMethodNameID.MSDK_PUSH_CLEAR_LOCAL_NOTIFICATION
is the method ID of clearing all local pushes
- Push callback methods
MSDKMethodNameID.MSDK_PUSH_TEXT_MESSAGE
is the general message callback IDMSDKMethodNameID.MSDK_PUSH_NOTIFICATION_SHOW
is the push display callback IDMSDKMethodNameID.MSDK_PUSH_NOTIFICATION_CLICK
is the push click callback ID
- Basic calling methods
[info] Precautions
For the Android platform, you can distinguish in-app message callbacks, push display and push clicks, so you need to distinguish the MethodID of the callbacks. The universal message callback can be used for the callback of receiving messages in the app, including local app messages and remote app messages.
2.1.3 PushInterface interface
registerPush function
Register the channel's push function. After the registration is successful, the device can receive message push, including the case that the device re-registers the function after unregistering it
@Override public void registerPush(String account,String seqID) { // The channel's push registration logic ... // Return "Register push successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_REGISTER_PUSH, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
unregisterPush function
The device unregistering function. The device will not receive message push after unregistering the push function successfully.
@Override public void unregisterPush(String seqID) { // The device unregistering logic ... // Return "Unregister device successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_UNREGISTER_PUSH, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
setAccount function
The account setting function. Set the user's account to support pushing messages by account
@Override public void setAccount(String account, String seqID ) { // The account setting logic of the channel ... // Return "Set account successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_SET_ACCOUNT, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
deleteAccount function
The account deleting function. Delete the user's account that has been set.
@Override public void deleteAccount(String account, String seqID) { // The account deleting logic of the channel ... // Return "Delete account successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_DELETE_ACCOUNT, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
setTag function
The label setting function. Different tags can be set for different users to push different messages to different users according to their tags.
@Override public void setTag(String tag, String seqID) { // The tag setting logic of the channel ... // Return "Set the tag successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_SET_TAG, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
deleteTag function
The tag deleting function. Delete the user's tag that has been set.
@Override public void deleteTag(String tag, String seqID) { // The tag deleting logic of the channel ... // Return "Delete the tag successfully" MSDKRet result = new MSDKRet(MSDK_PUSH_DELETE_TAG, MSDKErrorCode.SUCCESS); IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
addLocalNotification function
The function of adding local push messages.
@Override public void addLocalNotification(MSDKLocalNotification localNotification, String seqID) { // The channel's logic of adding local push messages ... // [Optional] Return "Add local push messages successfully" // MSDKRet result = new MSDKRet(MSDK_PUSH_ADD_LOCAL_NOTIFICATION, MSDKErrorCode.SUCCESS); // IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
clearLocalNotifications function
Clear all local pushes.
@Override public void clearLocalNotifications(String seqID) { // The channel's logic of clearing all local pushes ... // [Optional] Return "Clear all local pushes successfully" // MSDKRet result = new MSDKRet(MSDK_PUSH_CLEAR_LOCAL_NOTIFICATION, MSDKErrorCode.SUCCESS); // IT.onPluginRetCallback(MSDKObserverID.MSDK_PUSH_OBSERVER_DELIVER_MESSAGE, result, seqID); }
[info] For details, please refer to Demo Code
2.2 iOS Platform
2.2.1 Class rule description
- Naming rules: Fixed as
MSDKPush + channel
, such as:MSDKPushXG
- Must implement the
MSDKPushDelegate
protocolregisterPush
function, which is used to register the channel's push function. The device can receive message push from the channel after registering the push function successfullyunregisterPush
function, which is used to unregister the channel's push function. The device can't receive message push from the channel after unregistering the push function successfullysetTag
function, which is used to set tags and can set different tags for different users, used to push different messages for different user tagsdeleteTag
function, which is used to delete tags, that is, to delete user tags that have been setsetAccount
function, which is used to set the user's account to support message push by accountdeleteAccount
function, which is used to delete the account set by the user- Note: Add the local push. The method of the local push has been provided by MSDK on the iOS platform. It does not need to be implemented by the channel's plugin itself, but the channel's plugin needs to provide the monitoring method of local push and give a callback when a local push is received.
2.2.2 Description of callback fields
As for the description of the callback function, please refer to Client Plugin Development Rules
observerID
: the callback function IDkObserverIDPushBaseRet
is used to return the call result of the push methodkObserverIDPushNotifyCallback
is used to return the message results related to push message
ret
: the callback result- The
ret
type of the Push module includes:InnerBaseRet
, which is used to return the call result of the push methodInnerPushRet
, which is used to return the results related to push messages. In addition to the basic result parameters,InnerPushRet
also includes:type
- 0 - Remote notification received by the app is in the front end
- 1 - Remote notification received by the app in the backend
- 2 - Local notification received by the app is in the front end
- 3 - Local notification received by the app in the backend
- If not sure, please fill in -1
notification
, the content of the notification
- The
methodNameID
Function ID defined by MSDK, used to define the callback method- Basic calling methods
kMethodNameRegisterPush
is the method ID of registering the channel pushkMethodNameUnregisterPush
is the method ID of unregistering the devicekMethodNameSetAccountPush
is the account setting method IDkMethodNameDeleteAccountPush
is the account deleting method IDkMethodNameSetTagForPush
is the tag setting method IDkMethodNameDeleteTagForPush
is the tag deleting method IDkMethodNameAddLocalNotify
is the method ID of adding local pushkMethodNameClearLocalNotify
is the method ID of clearing all local pushes
- Push callback methods
kMethodNameNotifyCallback
is the general message callback IDkMethodNameNotifyShow
is the push display callback IDkMethodNameNotifyClick
is the push click callback ID
- Basic calling methods
[info] Precautions
For the iOS platform, because there is no way to distinguish display and click callbacks, a universal callback can be used for callbacks
2.2.3 MSDKPushDelegate protocol
registerPush function
Register the channel's push function. After the registration is successful, the device can receive message push, including the case that the device re-registers the function after unregistering it
- (void)registerPush:(const MSDKBaseParams &)baseParams withAccount:(const std::string &)account { // The channel's push registration logic ... // Return "Register push successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameRegisterPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
unregisterPush function
The device unregistering function. The device will not receive message push after unregistering the push function successfully.
- (void)unregisterPush:(const MSDKBaseParams &)baseParams { // The device unregistering logic ... // Return "Unregister device successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameUnregisterPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
setAccount function
The account setting function. Set the user's account to support pushing messages by account
- (void)setAccount:(const MSDKBaseParams &)baseParams withAccount:(const std::string &)account { // The account setting logic of the channel ... // Return "Set account successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameSetAccountPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
deleteAccount function
The account deleting function. Delete the user's account that has been set.
- (void)deleteAccount:(const MSDKBaseParams &)baseParams withAccount:(const std::string &)account { // The account deleting logic of the channel ... // Return "Delete account successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameDeleteAccountPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
setTag function
The label setting function. Different tags can be set for different users to push different messages to different users according to their tags.
- (void)setTag:(const MSDKBaseParams &)baseParams withTag:(const std::string &)tag { // The tag setting logic of the channel ... // Return "Set the tag successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameSetTagForPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
deleteTag function
The tag deleting function. Delete the user's tag that has been set.
- (void)deleteTag:(const MSDKBaseParams &)baseParams withTag:(const std::string &)tag { // The tag deleting logic of the channel ... // Return "Delete the tag successfully" InnerBaseRet ret(MSDKError::SUCCESS); ret.methodNameID = kMethodNameDeleteTagForPush; MSDKInnerObserverHolder<InnerBaseRet>::CommitToTaskQueue(ret, kObserverIDPushBaseRet, baseParams.seqID); }
[info] For details, please refer to Demo Code
All rights reserved.