簡體   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