SDK API Guide
Last updated:2021-12-15
Expand all
SDK API Guide
SDK Initialization APIs
- JPushInterface.init(context, appkey: string, channel: string)
- Description:
- Initialization API. Call it in
app.uxinsideonCreate. After that, other modules can call SDK APIs throughthis.$app.JPushInterface.
- Initialization API. Call it in
- Parameters:
context: application contextappkey: the app key assigned after creating the app on the JPush websitechannel: channel name, default value:default-channel
- Example:
- Description:
this.JPushInterface = JPushInterface.init(this, "官网中创建应用后分配的appkey", "自定义channel");
this.JPushInterface = JPushInterface.init(this, "官网中创建应用后分配的appkey", "自定义channel");
This code block is shown in the floating window
- JPushInterface.setDebugMode(enable: boolean)
- Description:
- Enables or disables debug mode. When set to
true, the SDK prints more logs. When set tofalse, all SDK log output is disabled. It is recommended to call this beforeinit.
- Enables or disables debug mode. When set to
- Parameters:
enable: debug switch
- Example:
- Description:
JPushInterface.setDebugMode(true);
JPushInterface.setDebugMode(true);
This code block is shown in the floating window
Get JPush Registration ID
- JPushInterface.registrationID(callback: (code: number, regId: string) => void)
- Description:
- Gets the push
RegistrationID.
- Gets the push
- Parameters:
callback:RegistrationIDcallbackcode: error coderegID: pushRegistrationID
- Example:
- Description:
this.$app.JPushInterface.registrationID((code, regID) => {})
this.$app.JPushInterface.registrationID((code, regID) => {})
This code block is shown in the floating window
Vendor Push
- JPushInterface.registerQuickPush(callback: (code: number, msg: string) => void)
- Description:
- Registers vendor push.
- Parameters:
callback:- Returns the corresponding status code:
0for success,-1if the vendor does not support push
- Returns the corresponding status code:
- Description:
this.$app.JPushInterface.registerQuickPush((code, msg) => {})
this.$app.JPushInterface.registerQuickPush((code, msg) => {})
This code block is shown in the floating window
JPush Notifications
- JPushInterface.subscribeJPushNotify(callback: (title: string, content: string, url: string) => void)
- Description:
- Subscribes to JPush notification callbacks. When the app is in the foreground and receives a JPush notification configured not to display in the foreground (not a vendor push), the notification will not be shown in the system notification bar. Instead, it will be returned to the client through this callback.
- Parameters:
callback:- title, content, and target URL
- Description:
this.$app.JPushInterface.subscribeJPushNotify((title, content, url) => {})
this.$app.JPushInterface.subscribeJPushNotify((title, content, url) => {})
This code block is shown in the floating window
Custom Messages
- JPushInterface.subscribeJPushMessage(callback: (title: string, content: string, msgid: string, extra: object) => void)
- Description:
- Receives custom push messages through this API.
For custom messages, the SDK only passes the data through and does not display any UI.
- Receives custom push messages through this API.
- Parameters:
callback:- title, content, message ID, and extras object
- Description:
this.$app.JPushInterface.subscribeJPushMessage((title, content, msgid, extra) => {})
this.$app.JPushInterface.subscribeJPushMessage((title, content, msgid, extra) => {})
This code block is shown in the floating window
Tags and Alias
- JPushInterface.addTags(tags: [string], seq: number, callback: (code: number, tags: [string], seq: number) => void)
- Description:
- Calls this API to add tags and returns the result in the callback.
- Parameters:
tags- cannot be
nilor an empty collection - collection members must be of type
NSString - at least one tag must be set per call
- valid tag characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters
@!#$&*+=.| - limit: each tag can be up to 40 bytes; up to 1000 tags are supported, and the total length must not exceed 5 KB (measured in UTF-8)
- a single device supports up to 1000 tags; there is no global tag count limit for the app
- cannot be
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding
tagsand status code.0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.
- returns the corresponding
- Description:
this.$app.JPushInterface.addTags(["1", "2"], 0, (code, tags, seq) => {})
this.$app.JPushInterface.addTags(["1", "2"], 0, (code, tags, seq) => {})
This code block is shown in the floating window
- JPushInterface.setTags(tags: [string], seq: number, callback: (code: number, tags: [string], seq: number) => void)
- Description:
- Calls this API to set tags and returns the result in the callback.
Note: this API overwrites existing tags instead of appending to them.
- Calls this API to set tags and returns the result in the callback.
- Parameters:
tags- cannot be
nilor an empty collection - collection members must be of type
NSString - at least one tag must be set per call
- valid tag characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters
@!#$&*+=.| - limit: each tag can be up to 40 bytes; up to 1000 tags are supported, and the total length must not exceed 5 KB (measured in UTF-8)
- a single device supports up to 1000 tags; there is no global tag count limit for the app
- cannot be
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding
tagsand status code.0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.
- returns the corresponding
- Description:
this.$app.JPushInterface.setTags(["1", "2"], 0, (code, tags, seq) => {})
this.$app.JPushInterface.setTags(["1", "2"], 0, (code, tags, seq) => {})
This code block is shown in the floating window
- JPushInterface.validateTag(tag: string, seq: number, callback: (code: number, tags: [string], seq: number, isVaild: boolean) => void)
- Description:
- Calls this API to verify whether the target tag has already been set.
- Parameters:
tag- cannot be
nilor an empty string - valid tag characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters
@!#$&*+=.| - each tag can be up to 40 bytes
- cannot be
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding
tagsand status code.0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.isVaildindicates whether the queried tag is already bound.
- returns the corresponding
- Description:
this.$app.JPushInterface.validateTag("1", 0, (code, tags, seq, isVaild) => {})
this.$app.JPushInterface.validateTag("1", 0, (code, tags, seq, isVaild) => {})
This code block is shown in the floating window
- JPushInterface.deleteTags(tags: [string], seq: number, callback: (code: number, tags: [string], seq: number) => void)
- Description:
- Calls this API to delete tags and returns the result in the callback.
- Parameters:
tags- cannot be
nilor an empty collection - collection members must be of type
NSString - at least one tag must be provided per call
- valid tag characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters
@!#$&*+=.| - limit: each tag can be up to 40 bytes; up to 1000 tags are supported, and the total length must not exceed 5 KB (measured in UTF-8)
- cannot be
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding
tagsand status code.0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.
- returns the corresponding
- Description:
this.$app.JPushInterface.deleteTags(["1", "2"], 0, (code, tags, seq) => {})
this.$app.JPushInterface.deleteTags(["1", "2"], 0, (code, tags, seq) => {})
This code block is shown in the floating window
- JPushInterface.cleanTags(seq: number, callback: (code: number, tags: [string], seq: number) => void)
- Description:
- Calls this API to remove all tags and returns the result in the callback.
- Parameters:
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding status code.
0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.tagshas no meaning here.
- returns the corresponding status code.
- Description:
this.$app.JPushInterface.cleanTags(0, (code, tags, seq) => {})
this.$app.JPushInterface.cleanTags(0, (code, tags, seq) => {})
This code block is shown in the floating window
- JPushInterface.getAllTags(seq: number, callback: (code: number, tags: [string], seq: number) => void)
- Description:
- Calls this API to get all tags.
- Parameters:
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding status code.
0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.tagscontains all currently configured tags.
- returns the corresponding status code.
- Description:
this.$app.JPushInterface.getAllTags(0, (code, tags, seq) => {})
this.$app.JPushInterface.getAllTags(0, (code, tags, seq) => {})
This code block is shown in the floating window
- JPushInterface.setAlias(alias: string, seq: number, callback: (code: number, alias: string, seq: number) => void)
- Description:
- Calls this API to set an alias.
- Parameters:
alias- cannot be
nilor an empty string - valid alias characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters
@!#$&*+=.| - each alias can be up to 40 bytes
- cannot be
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding
aliasand status code.0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.
- returns the corresponding
- Description:
this.$app.JPushInterface.setAlias("1", 0, (code, alias, seq) => {})
this.$app.JPushInterface.setAlias("1", 0, (code, alias, seq) => {})
This code block is shown in the floating window
- JPushInterface.deleteAlias(seq: number, callback: (code: number, alias: string, seq: number) => void)
- Description:
- Calls this API to delete the alias.
- Parameters:
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding status code.
0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.aliashas no meaning here.
- returns the corresponding status code.
- Description:
this.$app.JPushInterface.deleteAlias(0, (code, alias, seq) => {})
this.$app.JPushInterface.deleteAlias(0, (code, alias, seq) => {})
This code block is shown in the floating window
- JPushInterface.getAlias(seq: number, callback: (code: number, alias: string, seq: number) => void)
- Description:
- Calls this API to get the current alias.
- Parameters:
seq- the sequence number passed in the request, returned unchanged in the callback
callback- returns the corresponding status code.
0means success. For other return values, see the error code definitions.seqis the session sequence number passed in the request.aliasis the current alias.
- returns the corresponding status code.
- Description:
this.$app.JPushInterface.getAlias(0, (code, alias, seq) => {})
this.$app.JPushInterface.getAlias(0, (code, alias, seq) => {})
This code block is shown in the floating window
Stop and Resume Push Service
- JPushInterface.stopPush()
- Description:
- Stops the push service.
After this API is called, the JPush push service is completely stopped. Specifically:- push messages can no longer be received
- all other JPush APIs become invalid
- calling
JPushInterface.initcannot restore push; you must callresumePush
- Stops the push service.
- Description:
this.$app.JPushInterface.stopPush()
this.$app.JPushInterface.stopPush()
This code block is shown in the floating window
- JPushInterface.resumePush()
- Description:
- Resumes the push service.
After this API is called, JPush resumes normal operation completely.
- Resumes the push service.
- Description:
this.$app.JPushInterface.resumePush()
this.$app.JPushInterface.resumePush()
This code block is shown in the floating window
- JPushInterface.isPushStopped()
- Description:
- Checks whether the Push Service has been stopped.
- Description:
this.$app.JPushInterface.isPushStopped().then((isStoped) => {
})
this.$app.JPushInterface.isPushStopped().then((isStoped) => {
})
This code block is shown in the floating window
Set Mobile Number
- JPushInterface.setMobile(mobile: string, callback: (code: number, msg: string) => void)
- Description:
- Calls this API to set the mobile number.
- Parameters:
mobile: mobile number. It can only start with+or a digit. The remaining content can contain only-and digits, and the total length must not exceed 20. Passingnilor an empty string unbinds the number.callback- returns the corresponding status code.
0means success. For other return values, see the error code definitions.
- returns the corresponding status code.
- Description:
this.$app.JPushInterface.setMobile("11100002222", (code, msg) => {})
this.$app.JPushInterface.setMobile("11100002222", (code, msg) => {})
This code block is shown in the floating window
Notification Click Reporting
- JPushInterface.notificationReceive(query, callback: (param) => void)
- Description:
- Quick App does not provide a dedicated push click handling API, so you need to add click reporting logic on pages that may be opened from a push notification. Add this API call in the page's
onInitandonRefresh.
- Quick App does not provide a dedicated push click handling API, so you need to add click reporting logic on pages that may be opened from a push notification. Add this API call in the page's
- Parameters:
query: parameters passed when the page is opened; internally includes the JPush message IDcallback: callback for theextrafield in the notification
- Description:
onInit(query) {
this.$app.JPushInterface.notificationReceive(query, (param) => {
})
},
onRefresh(query) {
this.$app.JPushInterface.notificationReceive(query, (param) => {
})
}
param 为 JPush 透传参数
onInit(query) {
this.$app.JPushInterface.notificationReceive(query, (param) => {
})
},
onRefresh(query) {
this.$app.JPushInterface.notificationReceive(query, (param) => {
})
}
param 为 JPush 透传参数
This code block is shown in the floating window
Custom Message Click Reporting
- JPushInterface.customNotificationReceive(msgid: string)
- Description:
- Developers call this API to report clicks for custom notification messages.
- Parameters:
msgid: JPush message ID
- Description:
this.$app.JPushInterface.customNotificationReceive(msgid)
this.$app.JPushInterface.customNotificationReceive(msgid)
This code block is shown in the floating window
Get Current Connection State
- JPushInterface.getConnectionState()
- Description:
- Gets the current connection state. Returns a boolean value.
- Description:
var state = this.$app.JPushInterface.getConnectionState()
var state = this.$app.JPushInterface.getConnectionState()
This code block is shown in the floating window
Set Allowed Push Time
- JPushInterface.setPushTime(weekDays: Set
, startHour: number, endHour: number) - Description:
- By default, users can receive push notifications at any time. Developers can call this API to define the allowed push time period. If a notification arrives outside the allowed period, the SDK discards it. This is implemented purely on the client side, so it is unrelated to whether the client time or time zone is accurate. This API affects only notifications; custom messages are not affected.
- Parameters:
weekDays0means Sunday,1means Monday, and so on- uses a 7-day system; valid values in the set range from
0to6 - if the set is
null, notifications can be received at any time - if the set size is
0, notifications cannot be received at any time
startHour- start time of the allowed push window (24-hour format, range
0to23)
- start time of the allowed push window (24-hour format, range
endHour- end time of the allowed push window (24-hour format, range
0to23)
- end time of the allowed push window (24-hour format, range
- Description:
var weekDays = new Set([0])
this.$app.JPushInterface.setPushTime(weekDays, 0, 12)
var weekDays = new Set([0])
this.$app.JPushInterface.setPushTime(weekDays, 0, 12)
This code block is shown in the floating window
Client Error Codes
| Code | Description | Details |
|---|---|---|
| 6001 | Invalid setting; both tag and alias cannot be null | |
| 6002 | Tag/alias timeout | No response within 20 seconds after the API call |
| 6003 | Invalid alias string | Valid aliases and tags can contain letters (case-sensitive), numbers, underscores, and Chinese characters |
| 6004 | Alias too long, maximum 40 bytes | Chinese characters are 3 bytes in UTF-8 |
| 6005 | An individual tag string is invalid | Valid aliases and tags can contain letters (case-sensitive), numbers, underscores, and Chinese characters |
| 6006 | A tag is too long, maximum 40 bytes per tag | Chinese characters are 3 bytes in UTF-8 |
| 6007 | Too many tags, maximum 1000 | This is a per-device limit. There is no global tag limit for an app. |
| 6008 | Total tag length exceeds the limit | Total length must not exceed 5 KB |
| 6009 | Unknown error | An unexpected SDK exception occurred |
| 6011 | Tag or alias set more than 10 times within 10 seconds | The operation is being performed too frequently in a short time |
| 6014 | Request busy | The request frequency is too high. This request failed. Please try again. |
| 6015 | Blacklist | The user has been added to the blacklist |
| 6016 | Invalid user | The request for this invalid user failed |
| 6017 | Invalid request | The request contains abnormal parameters and is invalid |
| 6018 | Too many tags | This user already has more than 1000 tags and cannot set more |
| 6019 | Failed to get tags | An exception occurred while getting all tags |
| 6020 | Request failed | A special issue caused the request to fail |
| 6021 | A tags operation is already in progress | The previous tags request is still waiting for a response, so the next request cannot be executed yet |
| 6022 | An alias operation is already in progress | The previous alias request is still waiting for a response, so the next request cannot be executed yet |
Was this document helpful?