Reputation: 3340
I am trying to implement the pushbots code into my ionic app to have push notifications via - Pushbots docs
What I can't seem to figure out is where the following code goes:
if(PushbotsPlugin.isAndroid()){
PushbotsPlugin.initializeAndroid("PUSHBOTS_APP_ID", "GCM_SENDER_ID");
}
does it go in the below code if so where abouts:
.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();
}
});
})
or would it go in the config?
Upvotes: 0
Views: 1801
Reputation: 955
The initialization code for Pushbots should go into a function that is called when the 'deviceready' event is fired. In your case, given you have an Ionic project, the code should go into a $ionicPlatform.ready(function() {}) code block.
You can use the existing block:
.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();
}
});
})
Or you can create a separate block, to keep things clean and untangled:
.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();
}
});
})
Upvotes: 0