OneSignal subscribe user through web page using web-push-sdk

前端 未结 2 1520
鱼传尺愫
鱼传尺愫 2021-02-01 11:27

Is there a way in one signal web-push-sdk to add user manually and unsubscribe?

I tried this in my subscribeOneSignal() function but nothing happening.

2条回答
  •  佛祖请我去吃肉
    2021-02-01 11:38

    Nice, but I have used it, but it want users to be registered after they login to my site with their emailadress as tag:

    conn(),"SELECT * from members where id = '".$_SESSION['sesId']."'");
        if ($rr = mysqli_fetch_array($sr))
        {
            if ($rr['pushtag']==1 && $rr['alreadysendpush'] ==0 ) 
            {
            ?>
        var OneSignal = window.OneSignal || [];
        OneSignal.push(["init", {
          appId: "1c398831-ce91-4a8e-90d8-56cc40b8fa97",
          autoRegister:false,
          showCredit:false,
          disable:false, // betekend geen stanaard bericht als je geaceepteerd hebt notificaties te willen ontvangen
          notifyButton: {
            enable: true /* Set to false to hide */
          },
         safari_web_id: 'web.onesignal.auto.379e9ba9-232a-4433-a939-20e3e6310530'
        }]
        );
    
                                        OneSignal.push(function() {
                                          /* These examples are all valid */
                                          var isPushSupported = OneSignal.isPushNotificationsSupported();
                                          if (isPushSupported) 
                                          {
                                            // Push notifications are supported
    
    
                                                OneSignal.isPushNotificationsEnabled().then(function(isEnabled) 
                                                {
                                                    if (isEnabled)
                                                    {
                                                      console.log("Push notifications are enabled!"); 
                                                        OneSignal.sendTag("email", "", function(tagsSent) 
                                                        {
                                                            // Callback called when tags have finished sending                              
                                                            $.ajax({
                                                                type: "POST",
                                                                url: "inc/webpush.php",
                                                                data: {
                                                                    "email": "",
                                                                    "register": "1",
                                                                    "verification":""
                                                                },
                                                                dataType: "html"
                                                            }).done(function(e) {
    
    
                                                            });                                                     
                                                        })
                                                    }
                                                    else {
                                                      console.log("Push notifications are not enabled yet.");      
                                                    }
                                                  });
    
    
                                          } else {
                                            // Push notifications are not supported
                                          }
                                        });
            
    

    THis works sometimes with tags and sometimes without tags. How to make it work that i will only register with email

提交回复
热议问题