我正在尝试将pushbots代码实施到我的离子应用中以通过 - Pushbots docs
进行推送通知我似乎无法弄清楚以下代码的位置:
if(PushbotsPlugin.isAndroid()){
PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
}
如果是这样的话,是否会出现在下面的代码中:
.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();
}
});
})
还是会进入配置?
答案 0 :(得分:0)
Pushbots的初始化代码应该进入在触发'deviceready'事件时调用的函数。在您的情况下,假设您有一个Ionic项目,代码应该进入 $ ionicPlatform.ready(function(){})代码块。
您可以使用现有的块:
.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();
}
});
})
或者您可以创建一个单独的块,以保持清洁和解开:
.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();
}
});
})