Skip to content

Instantly share code, notes, and snippets.

Created March 9, 2015 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/aa3e6cc042b2b8486853 to your computer and use it in GitHub Desktop.
Save anonymous/aa3e6cc042b2b8486853 to your computer and use it in GitHub Desktop.
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase', 'ngCordova'])
.run(function($ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
// 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) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
// Check for network connection
if(window.Connection) {
if(navigator.connection.type == Connection.NONE) {
$ionicPopup.confirm({
title: 'No Internet Connection',
content: 'Sorry, no Internet connectivity detected. Please reconnect and try again.'
})
.then(function(result) {
if(!result) {
ionic.Platform.exitApp();
}
});
}
}
// Get permissions on first launch for notifications
if(ionic.Platform.isIOS()) {
window.plugin.notification.local.promptForPermission();
}
// Trigger alert when notification is fired but app is in foreground
window.plugin.notification.local.ontrigger = function (id, state, json) {
var notification = {
id: id,
state: state,
json: json
};
$timeout(function() {
console.log("triggered from " + notification);
$rootScope.$broadcast("cordovaLocalNotification:triggered", notification);
});
};
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment