登录后在Ionic app中设置OneSignal标签

时间:2017-03-28 15:58:07

标签: cordova ionic-framework cordova-plugins onesignal

用户登录我的应用后,我无法设置OneSignal标记。在我的登录控制器成功登录后,我已经包含了此代码,但没有运气。

if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                window.plugins.OneSignal.sendTag("email", $localStorage.email);
            }

我也尝试过没有条件但是得到了#34; ReferenceError:无法找到变量:cordova"

window.plugins.OneSignal.sendTag("email", $localStorage.email);

推送通知请求正在运行。我只是无法设置这些标签!

1 个答案:

答案 0 :(得分:1)

我自己就解决了这个问题!事实证明,这是正确的方法:

var notificationOpenedCallback = function(jsonData) {
      console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
    };

    window["plugins"].OneSignal
      .startInit("MY_APP_ID", "gcmid")
      .handleNotificationOpened(notificationOpenedCallback)
      .endInit();

这就像这样进入run函数:

.run(function($ionicPlatform, $localStorage, $sessionStorage, $state) {
  $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
      cordova.plugins.Keyboard.disableScroll(true);

      var notificationOpenedCallback = function(jsonData) {
          console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
        };

        window["plugins"].OneSignal
          .startInit("1a1bfc10-2a06-42b8-af98-ae1d8a55665e", "gcmid")
          .handleNotificationOpened(notificationOpenedCallback)
          .endInit()
          .sendTag("email", $localStorage.email);
    }
    if (window.StatusBar) {
      StatusBar.overlaysWebView(true);
      StatusBar.style(1);
    }

  });
})