Skip to content

Commit

Permalink
wrap in device ready - dont trust Meteor.startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Henriksen committed Jan 3, 2015
1 parent e12f7c6 commit 9902b8d
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions lib/client/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,60 +189,67 @@ Push.Configure = function(options) {
// Initialize on ready
Meteor.startup(function() {

// Update flag if app coldstart
document.addEventListener("pause", function() {
coldstart = false;
}, false);

var pushNotification = window.plugins.pushNotification;
document.addEventListener('deviceready', function() {

// Update flag if app coldstart
document.addEventListener("pause", function() {
coldstart = false;
}, false);

var pushNotification = window.plugins.pushNotification;

if (device.platform == 'android' || device.platform == 'Android') {
// alert('Rig GCM');
try {

if (options.gcm && options.gcm.projectNumber) {
pushNotification.register(function(result) {
// Emit registered
self.emit('register', result);
}, function(error) {
// Emit error
self.emit('error', { type: 'gcm.cordova', error: error });
}, {
'senderID': ''+options.gcm.projectNumber,
'ecb': 'onNotificationGCM'
});
} else {
// throw new Error('senderID not set in options, required on android');
console.warn('WARNING: Push.init, No gcm.projectNumber set on android');
}

} catch(err) {
// console.log('There was an error starting up push');
// console.log('Error description: ' + err.message);
self.emit('error', { type: 'gcm.cordova', error: err.message });
}
} else {
// alert('Rig APN');

if (device.platform == 'android' || device.platform == 'Android') {
try {
try {

if (options.gcm && options.gcm.projectNumber) {
pushNotification.register(function(result) {
// Emit registered
self.emit('register', result);
pushNotification.register(function(token) {
// Got apn / ios token
self.emit('token', { apn: token });
}, function(error) {
// Emit error
self.emit('error', { type: 'gcm.cordova', error: error });
self.emit('error', { type: 'apn.cordova', error: error });
}, {
'senderID': ''+options.gcm.projectNumber,
'ecb': 'onNotificationGCM'
});
} else {
// throw new Error('senderID not set in options, required on android');
console.warn('WARNING: Push.init, No gcm.projectNumber set on android');
'badge': ''+options.badge,
'sound': ''+options.sound,
'alert': ''+options.alert,
'ecb': 'onNotificationAPN'
}); // required!
} catch(err) {
// console.log('There was an error starting up push');
// console.log('Error description: ' + err.message);
self.emit('error', { type: 'apn.cordova', error: err.message });
}

} catch(err) {
// console.log('There was an error starting up push');
// console.log('Error description: ' + err.message);
self.emit('error', { type: 'gcm.cordova', error: err.message });
}
} else {

try {

pushNotification.register(function(token) {
// Got apn / ios token
self.emit('token', { apn: token });
}, function(error) {
// Emit error
self.emit('error', { type: 'apn.cordova', error: error });
}, {
'badge': ''+options.badge,
'sound': ''+options.sound,
'alert': ''+options.alert,
'ecb': 'onNotificationAPN'
}); // required!
} catch(err) {
// console.log('There was an error starting up push');
// console.log('Error description: ' + err.message);
self.emit('error', { type: 'apn.cordova', error: err.message });
}
}
}, false);

}, true);

});

}; // EO Push

0 comments on commit 9902b8d

Please sign in to comment.