The SDK lets you configure a custom namespace and JSAPI class name prefix for mini programs. To enable this feature, contact us.
Default behavior
By default, mini programs call JSAPIs using the WindVane namespace and the WV class name prefix:
const authorize = () =>{
window.WindVane.call('WVAuthorize', 'authorize', {}, function(e) { ... }, function(e) { ... });
};
document.addEventListener('WV.Event.WVBluetooth.characteristicValueChanged', function(e) { ... }, false);
To use a custom namespace and prefix, configure the following parameters in EMASMiniAppInitConfig:
|
Parameter |
Type |
Default |
Description |
|
|
String |
|
The window object name that mini programs use to access JSAPIs. |
|
|
String |
|
The class name prefix for JSAPI calls and event listeners. |
|
|
Boolean |
|
Specifies whether to maintain backward compatibility with mini programs that use the |
Configure custom namespace and prefix
New parameters
To use a custom namespace and prefix, configure the following parameters in EMASMiniAppInitConfig:
superAppNameSpace: Sets the window object name that mini programs use to access JSAPIs. The default value is "WindVane".jsApiClassNamePrefix: Sets the custom JSAPI class name prefix. The default value is "WV".windvaneBackwardCompatible: A Boolean that specifies whether to maintain backward compatibility with mini programs that use theWindVanenamespace andWVprefix. The default value is true.
|
Parameter |
Type |
Default |
Description |
|
|
String |
|
The window object name that mini programs use to access JSAPIs. |
|
|
String |
|
The class name prefix for JSAPI calls and event listeners. |
|
|
Boolean |
|
Specifies whether to maintain backward compatibility with mini programs that use the |
Set the three parameters in your initConfig method:
- (void)initConfig {
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
...
// New configuration items
miniAppInitConfig.windvaneBackwardCompatible = YES;
miniAppInitConfig.superAppNameSpace = @"your NameSpace";
miniAppInitConfig.jsApiClassNamePrefix = @"your ClassNamePrefix";
...
EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
}
Example
This example sets superAppNameSpace to "SuperApp" and jsApiClassNamePrefix to "SA":
- (void)initConfig {
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
...
// New configuration items
miniAppInitConfig.windvaneBackwardCompatible = YES;
miniAppInitConfig.superAppNameSpace = @"SuperApp";
miniAppInitConfig.jsApiClassNamePrefix = @"SA";
...
EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
}
With this configuration, the namespace changes from WindVane to SuperApp and the class name prefix changes from WV to SA. The following code shows JSAPI calls before and after the change:
// JSAPI call before customization
const authorize = () =>{
window.WindVane.call('WVAuthorize', 'authorize', {}, function(e) { ... }, function(e) { ... });
};
document.addEventListener('WV.Event.WVBluetooth.characteristicValueChanged', function(e) { ... }, false);
// JSAPI call after customization
const authorize = () =>{
window.SuperApp.call('SAAuthorize', 'authorize', {}, function(e) { ... }, function(e) { ... });
};
document.addEventListener('SA.Event.SABluetooth.characteristicValueChanged', function(e) {
...
}, false);
Configuration scenarios
Use the scenario that matches your mini program deployment:
Default namespace only: If all your mini programs use the default
WindVanenamespace andWVprefix, no configuration is required. The SDK applies these defaults automatically.Custom namespace only: If all your mini programs use a custom namespace and prefix, set
windvaneBackwardCompatibletoNO:
- (void)initConfig {
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
...
// New configuration items
miniAppInitConfig.windvaneBackwardCompatible = NO;
miniAppInitConfig.superAppNameSpace = @"your NameSpace";
miniAppInitConfig.jsApiClassNamePrefix = @"your ClassNamePrefix";
...
EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
}
Mixed: legacy and custom: If you need to support both older mini programs that use the
WindVane/WVidentifiers and newer mini programs that use a custom namespace and prefix, setwindvaneBackwardCompatibletoYES:
- (void)initConfig {
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
...
// New configuration items
miniAppInitConfig.windvaneBackwardCompatible = YES;
miniAppInitConfig.superAppNameSpace = @"your NameSpace";
miniAppInitConfig.jsApiClassNamePrefix = @"your ClassNamePrefix";
...
EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
}