2017-11-25 6 views
0

メンバーはリンクをクリックして通知を購読できるWordpressでOnesignalを使用しています。このリンクを変更して既に登録されているユーザーのメッセージを表示できますか?OneSignal - 既に購読しているメンバーに特定のメッセージを表示

これは私が試みたものです。このコードはまだ購読していない人の購読リンクを表示します。すでに購読している人は何も表示しません。私の "エコー"の功績はうまくいかないようです。

誰かが助けることができますか?

<body> 
<a href="#" id="subscribe-link" style="display: none;"></i><b> Subscribe to 
notifications </b></a> 
<script> 
    function subscribe() { 
     OneSignal.push(["registerForPushNotifications"]); 
     event.preventDefault(); 
    } 

    var OneSignal = OneSignal || []; 
    /* This example assumes you've already initialized OneSignal */ 
    OneSignal.push(function() { 
     // If we're on an unsupported browser, do nothing 
     if (!OneSignal.isPushNotificationsSupported()) { 
      return; 
     } 
     OneSignal.isPushNotificationsEnabled(function(isEnabled) { 
      if (isEnabled) { echo "You have already subscribed to notifications"; 

      } else { 
       document.getElementById("subscribe-link").addEventListener('click', subscribe); 
       document.getElementById("subscribe-link").style.display = ''; 
      } 
     }); 
    }); 
</script> 

`

答えて

0

あなたは(それを無効にしませんでした)Wordpressのプラグインを使用している場合は、registerForPushNotificationsを呼び出す必要はありません。

プラグインは、チェックするページでisPushNotificationsEnabledメソッドを使用できるように、OneSignal変数を設定する必要があります。

試してみてください。

OneSignal.push(function() { 
    OneSignal.isPushNotificationsEnabled().then(function(isEnabled) { 
    if (isEnabled) 
     console.log("Push notifications are enabled!"); 
    else 
     console.log("Push notifications are not enabled yet.");  
    }); 
}); 
関連する問題