在One Signal Web Push SDK中有没有一种方式可以手动添加用户并取消订阅?
我已经在我的subscribeOneSignal()
函数中尝试过,但没有任何反应。
OneSignal.push(function() {
OneSignal.registerForPushNotifications();
});
我有一个简单的HTML页面,上面有两个按钮:“订阅”和“取消订阅”。当用户点击“订阅”按钮时,应该将其添加到OneSignal中;当用户点击“取消订阅”按钮时,他不应该收到通知。
<!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>