简体   繁体   English

Onesignal推送通知到特定类别

[英]Onesignal Push Notification to specific category

I have a database of persons on my server and it contains a group number attribute. 我的服务器上有一个人的数据库,它包含一个group number属性。 I want to send separate notifications for each of the group. 我想为每个组发送单独的通知。 Using the following code, it will send a notification to all apps. 使用以下代码,它将向所有应用发送通知。 How do I set or subscribe the app so that it will know that a certain mobile belongs to a certain group? 如何设置或订阅应用程序,以便它知道某个手机属于某个组? Each of the members needs to login first before accessing the app. 每个成员都需要先登录才能访问该应用程序。

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();
    },
};

When a user subscribes to your app, you can get the OneSignal Player ID of the device and save it to your database. 当用户订阅您的应用程序时,您可以获取设备的OneSignal Player ID并将其保存到数据库中。

Anytime after the init call use getPermissionSubscriptionState method to get the Player ID. 初始化调用之后的任何时候,都可以使用getPermissionSubscriptionState方法获取播放器ID。

Then you can follow OneSignal's Database Integration Guide to associate the player ID with your user's and group number. 然后,您可以按照OneSignal的数据库集成指南将播放器ID与您的用户和组号相关联。

Another option is to use OneSignal Tagging Guide documentation to associate devices with groups. 另一个选择是使用《 OneSignal 标记指南》文档将设备与组关联。

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

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