× Requests and support related to jBackend.

Push notification, token ?

  • alphaa
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #5187 by alphaa
Replied by alphaa on topic Push notification, token ?
Thank again,

method : 'POST' don't change ?! as mehod : 'GET' ?

so now I want to insert this code in my app.js who look like :
angular.module('starter', [])

.run(function($ionicPlatform) {
  $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();
    }

Please Log in or Create an account to join the conversation.

More
8 years 8 months ago #5188 by admin
Replied by admin on topic Push notification, token ?
It works both way.

Please Log in or Create an account to join the conversation.

  • alphaa
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago - 8 years 8 months ago #5189 by alphaa
Replied by alphaa on topic Push notification, token ?
Hello ,
see it at my app.js
angular.module('starter', ['ionic', ...,'ngCordova'])

.run(function($log, $cordovaPush, $rootScope, $http, $ionicPlatform) {
    var androidConfig, iosConfig, register;
 
    androidConfig = {
        "senderID": " "
    };
    iosConfig = {
        "badge": true,
        "sound": true,
        "alert": true
    };
 
    function register(token, user_id, success, failure) {

        var platform = (ionic.Platform.isWebView()) ? ionic.Platform.platform() : 'generic';

        $http({
            method: 'POST',
            url: '{apppath}/appi/put/push/register',
            data: {
                token: token,
                appcode: {appcode}, // as declared under jBackend
                platform: platform,
                user_id: user_id
            }
        }).then(function(response) {
            success(response.data);
        }, function(response) {
            failure(response.data, response.status);
        });

    }
    return $ionicPlatform.ready(function() {
        if (ionic.Platform.isAndroid()) {
            $cordovaPush.register(androidConfig).then(function(result) {
                $log.debug('android push notification registration success', result);
            }, function(err) {
                $log.error('android push notification registration error', err);
            });
            return $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
                switch (notification.event) {
                    case 'registered':
                        if (!notification.regid.length) {
                            return;
                        }
                        $log.debug('registration ID', notification.regid);
                        register('Android', notification.regid).success(function() {
                            return $log.info('Push notif Token stored');
                        });
                        break;
                    case 'message':
                        $log.debug('Push notif message', notification);
                        if (notification.foreground) { // If your user is using the app
                            // Do something like opening the Post within the app
                            // You have access to
                            // notification.payload.id which is the new Post ID
                            // notification.payload.message which is the new Post Title
                        } else { // If your user has clicked on the notification
                            // Do something like opening the Post within the app
                            // You have access to
                            // notification.payload.id which is the new Post ID
                            // notification.payload.message which is the new Post Title
                        }
                        break;
                    case 'error':
                        $log.debug('Push notif error', notification);
                        break;
                }
            });
        } else if (ionic.Platform.isIOS()) {
            $cordovaPush.register(iosConfig).then(function(deviceToken) {
                register('iOS', deviceToken).success(function() {
                    return $log.info('Push notif Token stored');
                });
                $log.debug('iOS push notification registration success', deviceToken);
            }, function(err) {
                $log.error('iOS push notification registration error', err);
            });
            return $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
                $log.debug('Push notif message', notification);
                if (notification.alert) {
                    if (notification.foreground) { // If your user is using the app
                        // Do something like opening the Post within the app
                        // You have access to
                        // notification.id which is the new Post ID
                        // notification.alert which is the new Post Title
                    } else { // If your user has clicked on the notification
                        // Do something like opening the Post within the app
                        // You have access to
                        // notification.id which is the new Post ID
                        // notification.alert which is the new Post Title
                    }
                }
               ..
it run in browser but not in my device , it show a white page .

But if i do it
  .run(function($ionicPlatform) {
  $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();
...
    } 
its run normally in browser and device

What is the problem ?
Last edit: 8 years 8 months ago by alphaa.

Please Log in or Create an account to join the conversation.

More
8 years 8 months ago #5190 by admin
Replied by admin on topic Push notification, token ?
Sorry but it's hard to understand the problem just looking at these code sinppets. I would suggest you to check the console log for any error message.

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

  • alphaa
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #5192 by alphaa
Replied by alphaa on topic Push notification, token ?
Its right, srry fr my bad english.

so can you help to have a code for my app.js for working my push notification.
I have app code, sender id and api key.
If you do as the exemple for webservice jbackapp , it will be nice :)

Please Log in or Create an account to join the conversation.

More
8 years 8 months ago #5195 by admin
Replied by admin on topic Push notification, token ?
This is a good point, so I will try to release a new jBackApp demo version with support for push notification. I think I will be able to manage this in the next weeks (I am currently working to the next jBackend release, so I am messing with this code already).

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

Time to create page: 0.139 seconds