代码之家  ›  专栏  ›  技术社区  ›  beginner

Onesignal推送通知到特定类别

  •  0
  • beginner  · 技术社区  · 6 年前

    我的服务器上有一个人员数据库,其中包含 group number 属性我想为每个组分别发送通知。使用以下代码,它将向所有应用程序发送通知。我如何设置或订阅应用程序,以便它知道某个手机属于某个组?每个成员在访问应用程序之前都需要先登录。

    var app = {
        // Application Constructor
        initialize: function() {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        // deviceready Event Handler
        //
        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicitly call 'app.receivedEvent(...);'
        onDeviceReady: function() {
            console.log('Received Device Ready Event');
            console.log('calling setup push');
            // Set your iOS Settings
            var iosSettings = {};
            iosSettings["kOSSettingsKeyAutoPrompt"] = false;
            iosSettings["kOSSettingsKeyInAppLaunchURL"] = true;
    
            window.plugins.OneSignal
              .startInit("3074529d MY APP ID HERE d5eb61b000")
              .handleNotificationReceived(function(jsonData) {
                alert("Notification received: \n" + JSON.stringify(jsonData));
                console.log('Did I receive a notification: ' + JSON.stringify(jsonData));
              })
              .handleNotificationOpened(function(jsonData) {
                alert("Notification opened: \n" + JSON.stringify(jsonData));
                console.log('didOpenRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
              })
              .inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.InAppAlert)
              .iOSSettings(iosSettings)
              .endInit();
        },
    };
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   JonF    6 年前

    当用户订阅您的应用程序时,您可以获取设备的OneSignal Player ID并将其保存到您的数据库中。

    初始化调用后的任何时间使用 getPermissionSubscriptionState 方法获取播放器ID。

    然后你可以跟踪OneSignal的 Database Integration Guide 将玩家ID与用户和组号关联。

    另一种选择是使用OneSignal Tagging Guide documentation 将设备与组关联。