Ejemplo n.º 1
0
            window.onNotificationAPN = function(evnt) {
                // log(evnt.payload, evnt, evnt.alert);

                // we do not support sound yet...
                // if (evnt.sound) {
                //     var snd = new Media(evnt.sound);
                //     snd.play();
                // }

                customReceiveHook();

                if (evnt.alert) {
                    common.vibrate(500, app.user.get('notify_settings'));

                    // show a short notify and add the message
                    // to the activity collection
                    common.notify(evnt.alert, 20000);

                    app.activityCollection.addActivity({
                        key: 'push_notification',
                        data: {
                            body:      evnt.alert,
                            timestamp: new Date().getTime()
                        }
                    });
                }

                if (evnt.badge) {
                    app.pushNotification.setApplicationIconBadgeNumber(function success() {
                        // log('ok set the badge......'); // XXX TODO raus
                    }, function error(e) { log(e); }, evnt.badge);
                }

                // custom data
                // the phonegap "push-plugin" cannot read this at all?
                // ------- however:
                // NOT NEEDED, resume should be enough
                /*if (evnt.payload && evnt.payload.type) {
                    if(evnt.payload.type === 'invitation') {
                        app.fetchUser();
                    }
                }*/
            };
Ejemplo n.º 2
0
            window.onNotificationGCM = function(e) {
                switch( e.event ) {
                case 'registered':
                    if ( e.regid.length > 0 ) {
                        setTimeout(function() {
                            sendRegIDToServer(e.regid);
                        }, 1000);

                        // Your GCM push server needs to know the regID before it can push to this device
                        // here is where you might want to send it the regID for later use.
                        log('REGISTERED -> REGID:' + e.regid);
                    }
                    break;

                case 'message':
                    customReceiveHook();

                    var msg = e && e.payload ? e.payload.message : 'no message';

                    // log(JSON.stringify(e));

                    // if the foreground flag is set, this notification happened while we were in the foreground.
                    // you might want to play a sound to get the user's attention, throw up a dialog, etc.
                    if (e.foreground || e.coldstart) {
                        // log('--INLINE NOTIFICATION--');

                        common.vibrate(500, app.user.get('notify_settings'));
                        setTimeout(function() {
                            common.notify(msg, 20000);
                        }, 1500);

                        // if the notification contains a soundname, play it.
                        // TODO sound var my_media = new Media('/android_asset/www/' + e.soundname);
                        // my_media.play();
                    }
                    // otherwise we were launched because the user touched a notification in the notification tray.
                    /*else {
                        if (e.coldstart) {
                            // log('-COLDSTART NOTIFICATION--');
                        }
                        else {
                            // log('-BACKGROUND NOTIFICATION--');
                        }
                    }*/

                    // in all cases:
                    app.activityCollection.addActivity({
                        key: 'push_notification',
                        data: {
                            body:      msg,
                            timestamp: new Date().getTime()
                        }
                    });

                    break;

                case 'error':
                    log('onNotificationGCM ERROR: ' + e.msg);
                    app.handleError(e.msg, true);
                    break;

                default:
                    log('EVENT -> Unknown, an event was received and we do not know what it is');
                    break;
                }
            };