繁体   English   中英

Onesignal推送通知到特定类别

[英]Onesignal Push Notification to specific category

我的服务器上有一个人的数据库,它包含一个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();
    },
};

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

初始化调用之后的任何时候,都可以使用getPermissionSubscriptionState方法获取播放器ID。

然后,您可以按照OneSignal的数据库集成指南将播放器ID与您的用户和组号相关联。

另一个选择是使用《 OneSignal 标记指南》文档将设备与组关联。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM