You can call this interface to remove native notification listening.
removeNotifyListener API usage instruction
AlipayJSBridge.call('removeNotifyListener', {
name: 'fortest'
}, function (result) {
console.log(result);
});
Code sample
The following example shows the basic functions.
<h1>Click the following button to perform a test.</h1>
<p>In this example, multiple operations are called on the same page. This API supports communication among different apps.</p>
<a href="#" class="btn start">Start listening.</a>
<a href="#" class="btn stop">Stop listening.</a>
<a href="#" class="btn send">Send a notification.</a>
<script>
function callback(e){
alert(JSON.stringify(e));
};
function ready(callback) {
// Call JS Bridge if it has been injected.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Listen to the injection event if it has not been injected.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('.start').addEventListener('click', function() {
AlipayJSBridge.call('addNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
}, callback);
});
document.querySelector('.stop').addEventListener('click', function() {
AlipayJSBridge.call('removeNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
}, function(e) {
alert(JSON.stringify(e));
});
});
document.querySelector('.send').addEventListener('click', function() {
AlipayJSBridge.call('postNotification', {
name:'TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
data: {
hello: 'world'
}
});
});
});
</script>
API
AlipayJSBridge.call('removeNotifyListener', {
name
}, fn)
Input parameters
Name | Type | Description | Required | Default value |
---|---|---|---|---|
name | String | Notification name | Y | “” |
fn | function | Callback function | N | - |
Output parameters
result: {success}
: the parameter transferred in the callback function.
Name | Type | Description |
---|---|---|
success | bool | Whether notification listening is removed successfully |
Error code
Error code | Description |
---|---|
4 | Unauthorized call |
Precautions
success: true
is returned regardless of whether the remove operation is registered.