首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pushbots和Ionic应用程序

Pushbots和Ionic应用程序
EN

Stack Overflow用户
提问于 2015-08-17 14:44:28
回答 1查看 1.8K关注 0票数 0

我正在尝试在我的离子应用程序中实现推机器人代码,以便通过- Pushbots博士进行推送通知。

我似乎无法弄清楚以下代码的去向:

代码语言:javascript
复制
if(PushbotsPlugin.isAndroid()){
    PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
}

如果是这样的话,它会在下面的代码中吗?

代码语言:javascript
复制
    .run(function($ionicPlatform, $ionicAnalytics, $window) {

  $ionicPlatform.ready(function() {


  /*  $ionicAnalytics.register();*/
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }

    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

或者它会被放入配置中?

EN

回答 1

Stack Overflow用户

发布于 2015-08-17 15:45:15

Pushbots的初始化代码应该进入一个在触发“deviceready”事件时调用的函数。在您的情况下,如果您有一个Ionic项目,代码应该进入一个$ionicPlatform.ready(function() {})代码块。

您可以使用现有的块:

代码语言:javascript
复制
.run(function($ionicPlatform, $ionicAnalytics, $window) {

  $ionicPlatform.ready(function() {
    if(PushbotsPlugin.isAndroid()){
        PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
    }

    /*  $ionicAnalytics.register();*/
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }

    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

或者你可以创建一个单独的块,以保持事物的清洁和混乱:

代码语言:javascript
复制
.run(function($ionicPlatform, $ionicAnalytics, $window) {

  $ionicPlatform.ready(function() {
    if(PushbotsPlugin.isAndroid()){
        PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
    }
  });

  $ionicPlatform.ready(function() {
    /*  $ionicAnalytics.register();*/
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }

    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32053317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档