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.ux inside onCreate. After that, other modules can call SDK APIs through this.$app.JPushInterface.
    • Parameters:
      • context: application context
      • appkey: the app key assigned after creating the app on the JPush website
      • channel: channel name, default value: default-channel
    • Example:
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 to false, all SDK log output is disabled. It is recommended to call this before init.
    • Parameters:
      • enable: debug switch
    • Example:
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.
    • Parameters:
      • callback: RegistrationID callback
        • code: error code
        • regID: push RegistrationID
    • Example:
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: 0 for success, -1 if the vendor does not support push
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
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.
    • Parameters:
      • callback:
        • title, content, message ID, and extras object
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 nil or 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
      • seq
        • the sequence number passed in the request, returned unchanged in the callback
      • callback
        • returns the corresponding tags and status code. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request.
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.
    • Parameters:
      • tags
        • cannot be nil or 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
      • seq
        • the sequence number passed in the request, returned unchanged in the callback
      • callback
        • returns the corresponding tags and status code. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request.
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 nil or an empty string
        • valid tag characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|
        • each tag can be up to 40 bytes
      • seq
        • the sequence number passed in the request, returned unchanged in the callback
      • callback
        • returns the corresponding tags and status code. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request. isVaild indicates whether the queried tag is already bound.
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 nil or 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)
      • seq
        • the sequence number passed in the request, returned unchanged in the callback
      • callback
        • returns the corresponding tags and status code. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request.
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. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request. tags has no meaning here.
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. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request. tags contains all currently configured tags.
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 nil or an empty string
        • valid alias characters: letters (case-sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|
        • each alias can be up to 40 bytes
      • seq
        • the sequence number passed in the request, returned unchanged in the callback
      • callback
        • returns the corresponding alias and status code. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request.
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. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request. alias has no meaning here.
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. 0 means success. For other return values, see the error code definitions. seq is the session sequence number passed in the request. alias is the current alias.
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.init cannot restore push; you must call resumePush
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.
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.
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. Passing nil or an empty string unbinds the number.
      • callback
        • returns the corresponding status code. 0 means success. For other return values, see the error code definitions.
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 onInit and onRefresh.
    • Parameters:
      • query: parameters passed when the page is opened; internally includes the JPush message ID
      • callback: callback for the extra field in the notification
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
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.
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:
      • weekDays
        • 0 means Sunday, 1 means Monday, and so on
        • uses a 7-day system; valid values in the set range from 0 to 6
        • 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 0 to 23)
      • endHour
        • end time of the allowed push window (24-hour format, range 0 to 23)
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?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 Shenzhen Hexun Huagu Information Technology Co., Ltd.

Open in Docs Center