Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

notification callback function only works in the app?

Am I correct in believing that the callback function is only executed if the app is actually currently open on the iPhone ?

This is the code I have in my app.js

// register for push notifications
Titanium.Network.registerForPushNotifications({
    types: [
        Titanium.Network.NOTIFICATION_TYPE_BADGE,
        Titanium.Network.NOTIFICATION_TYPE_ALERT,
        Titanium.Network.NOTIFICATION_TYPE_SOUND
    ],
    success:function(e)
    {
         var deviceToken = e.deviceToken;
          label.text = "Device registered. Device token: \n\n"+deviceToken;
       Ti.API.info("Push notification device token is: "+deviceToken);
       Ti.API.info("Push notification types: "+Titanium.Network.remoteNotificationTypes);
       Ti.API.info("Push notification enabled: "+Titanium.Network.remoteNotificationsEnabled);
    },
    error:function(e)
    {
      label.text = "Error during registration: "+e.error;
    },
    callback:function(e)
    {
          var myjobid = e.data.jobid;
          alert('Notification received:' + myjobid);
          var Props = Titanium.App.Properties;
          Props.setString('notify', myjobid);
        }
});

My payload is like this:

 aps => {
      badge => 3,
      jobid => "2513751",
    },

If I'm actually in the app, when I send a notification to it the alert notification and the correct jobid displayed. I can then retrieve that jobid elsewhere in my app using this:

var myjobid = Props.getString('notify');

However, if I'm not in the app, and I send my app a notification the badge changes correctly, but I don't see an alert and the Props getstring(jobid) returns nothing.

It's as if the callback isn't firing unless I'm in the app.. is that what it should do ?

Is there no way to deliver a payload unless I'm in the app ?

— asked June 9th 2010 by David Brown
  • callback
  • notification
  • notifications
  • payload
1 Comment
  • Did you ever found out how to make this work?

    — commented October 14th 2011 by Julian Castaneda

2 Answers

  • bump

    — answered April 5th 2011 by Matt Apperson
    permalink
    0 Comments
  • i think you have to register to push service in the "success" case

    — answered October 14th 2011 by Samuele Coppedè
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.