# Other

# onCustomEvent

onCustomEvent(callback)

Listens for the "onCustomEvent" event sent by the native side.

iOS Invocation Method

Android Invocation Method

Harmony Invocation Method

Sample Code

const callback = (res) => {
    console.log(res) // Get the parameters passed from the native side
}
ft.onCustomEvent(callback)

# offCustomEvent

offCustomEvent(callback)

Cancels listening for the onCustomEvent event. When the callback is empty, clears all callbacks.

Sample Code

const callback = (res) => {}
ft.onCustomEvent(callback)

// Clear the specified callback
ft.offCustomEvent(callback)
// Clear all callbacks
ft.offCustomEvent()

# addCustomEventListener

addCustomEventListener(eventName, callback)

This event is a wrapper based on onCustomEvent, which can effectively reduce the boilerplate code inside onCustomEvent.

Note When using this event, for it to trigger normally, the data body when the SDK calls the event must have a name field indicating which eventName is being triggered.

For example:

{
  name: 'someMethod', // Required field
  data: {
    a: 'data-1',
    b: 'data-2',
    c: 1001
  },
  errMsg: 'some error msg'
}

The entire data will be passed through to the callback.

Sample Code

const callback = (res) => {
    console.log(res) // Get the parameters passed from the native side
}
ft.addCustomEventListener('someMethod', callback)

# removeCustomEventListener

removeCustomEventListener(eventName, callback)

Removes the listener added by addCustomEventListener.

Sample Code

const callback = (res) => {
    console.log(res) // Get the parameters passed from the native side
}
ft.removeCustomEventListener('someMethod', callback)

# sendWebviewEvent

ft.sendWebviewEvent(Object object, Object pageInstance)

The Mini-Program sends an event to H5. pageInstance represents the this instance of the current webview page.

Sample Code

 ft.sendWebviewEvent({ data: '456' }) // Send data to the webview of the current page
 ft.sendWebviewEvent({ data: '456' }, getCurrentPages()[0]) // Send data to the webview of the corresponding page

# reportEvent

Event reporting.

ft.reportEvent(string eventId, object data)

Parameters

Property Type Description
eventId string The unique event name set
data object An object that can be processed by JSON.stringify, which will be reported to the system together

# loadExtApi

loadExtApi(Object object)

Loads custom API configurations, equivalent to the configuration in FinClipConf.js.

For SDK-side configuration documentation, refer to:

iOS Custom API Configuration Documentation (opens new window)

Android Custom API Configuration Documentation (opens new window)

There are two methods to configure custom APIs:

  1. By creating a FinClipConf.js file in the root directory.

  2. By using the ft.loadExtApi API.

The parameters used by both methods are the same.

Parameters

The parameters for a single API item are as follows:

Property Type Required Description
name string Yes Custom API name
sync boolean No Whether it is a synchronous API
overwrite boolean No Whether to overwrite an API with the same name
pluginId array or string No This parameter is only effective when loadExtApi is called within a Mini-Program, indicating that plugins whose IDs are in the list are allowed to use this custom API
scope string No Supported from Base Library 3.5.6 onwards. Only effective when loadExtApi is called within a plugin. Optional values are default, self, all. The default value is default.
params object No Parameter format. Only required properties can be listed. If there are no restrictions, an empty object can be used directly.

Valid values for object.scope

Value Description
default Indicates the API is registered to the Mini-Program's ft and the plugin's own ft.
self Indicates the API is only registered to its own ft and can only be called internally by itself.
all Indicates the API is registered to the Mini-Program's ft and all plugin ft instances. Other plugins can call the API registered by this plugin.

Sample Code

// FinClipConf.js
module.exports = {
  extApi:[
    {
      name: 'finclipLogin',
      sync: false,
      params: {
        url: ''
      }
    }
  ]
}

Sample Code

// loadExtApi parameters are the same as FinClipConf.js
ft.loadExtApi([
    {
      name: 'finclipLogin',
      sync: false,
      params: {
        url: ''
      }
    },
    {
      name: 'finclipTestSync',
      sync: true,
      params: {
          name:'',
          title:''
      }
    }
  ])

// Asynchronous call example
ft.finclipLogin({
  url: 'some url'
  success: (res) => { console.log(res) },
  fail: (res) => { console.log(res) },
})

// Synchronous call example
const res = ft.finclipTestSync({ name: '', title: ''})
console.log(res)
© FinClip with ❤ , Since 2017