在一個信號web-push-sdk中手動添加用戶並取消訂閱有什麼方法嗎?OneSignal使用web-push-sdk通過網頁訂閱用戶
我在subscribeOneSignal()
功能,但沒有發生嘗試這個。
OneSignal.push(function() {
OneSignal.registerForPushNotifications();
});
我有簡單的HTML頁面,在這裏我有兩個按鈕,一個「訂閱」等是「退訂」,現在當上訂閱按鈕,用戶點擊他應該在一個信號增加,當他點擊「取消」按鈕他不應該收到通知。
<!DOCTYPE html>
<html>
<head>
<link rel="manifest" href="/manifest.json">
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "345345-asdf-345",
autoRegister: false,
notifyButton: {
enable: true
}
}]);
function subscribeOneSignal(){
OneSignal.push(function() {
OneSignal.registerForPushNotifications();
});
OneSignal.push(function() {
OneSignal.registerForPushNotifications({
modalPrompt: true
});
});
}
function unSubscribeOneSignal(){
//unsubscribe functionality goes here
}
</script>
</head>
<body>
<p>OneSingle Testing</p>
<br>
<button onclick="subscribeOneSignal()">Subscribe </button>
<button onclick="unSubscribeOneSignal()">Unsubscribe </button>
</body>
</html>
我不知道onesignal,但我已經爲您的Pushpad的確切用例(訂閱/取消訂閱按鈕)寫了一個示例:請參閱[「按鈕」示例](https://pushpad.xyz/docs/javascript_sdk_examples) – collimarco