This API removes a listener for native notifications.
Using the removeNotifyListener API
AlipayJSBridge.call('removeNotifyListener', {
name: 'fortest'
}, function (result) {
console.log(result);
});Code example
This example demonstrates the basic functionality.
<h1>Click the buttons below to test</h1>
<p>This only tests the case within the same page. This API can communicate between different applications.</p>
<a href="#" class="btn start">Start Listener</a>
<a href="#" class="btn stop">Stop Listener</a>
<a href="#" class="btn send">Send Notification</a>
<script>
function callback(e){
alert(JSON.stringify(e));
};
function ready(callback) {
// If AlipayJSBridge is injected, call the function directly.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// If not, listen for the injection event.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('.start').addEventListener('click', function() {
AlipayJSBridge.call('addNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT' // Events sent from H5 pages must start with NEBULANOTIFY_ to be listened for.
}, callback);
});
document.querySelector('.stop').addEventListener('click', function() {
AlipayJSBridge.call('removeNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT' // Events sent from H5 pages must start with NEBULANOTIFY_ to be listened for.
}, function(e) {
alert(JSON.stringify(e));
});
});
document.querySelector('.send').addEventListener('click', function() {
AlipayJSBridge.call('postNotification', {
name:'TEST_EVENT', // Events sent from H5 pages must start with NEBULANOTIFY_ to be listened for.
data: {
hello: 'world'
}
});
});
});
</script>API
Important
The remove operation returns success: true even if the listener is not registered.
AlipayJSBridge.call('removeNotifyListener', {
name
}, fn)Input parameters
Name | Type | Description | Required | Default |
name | String | Notification name. | Yes | "" |
fn | Function | Callback function. | N | - |
Output parameters
The result: {success} parameter is passed to the callback function.
Name | Type | Description |
success | bool | Was it removed successfully? |
Error codes
Error code | Description |
4 | No permission to call. |