Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:30:25+00:00 2026-06-17T14:30:25+00:00

I asked this question on the developers forum too, but as my time is

  • 0

I asked this question on the developers forum too, but as my time is running out I hoped posting on stackoverflow might be quicker.

Currently I am able to receive push notifications and I want to send some extra data along, after searching around I concluded that this should be possible. The idea is to set the messages from a users inbox (in the app) when a push notification is fired, so a users gets a push notification that says “New message” and along with it is the message send in a different key which is supposed to be saved in the Applications.Properties when the push notifications callback function is called.

However, the callback function is never triggered. The notifications are send, the badge is set to what my php script does so is the message. To test if the callback was triggered I changed the badge and message to hardcoded values (see below), I got this code from mainly from ios muncher but I assumed that the alert in the callback would be the one shown to the user.

A different thing I noticed, I only receive push notifications when the user is not using the app, so when it is running in the background. When a user is using the app push notifications are not shown, I thought that this might be because the callback is not triggered.

Thanks in advance for all kind help.

Below some code:

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;  
            Ti.API.info("Push notification device token is: "+deviceToken);  

            //alert('device token is' +e.deviceToken);  
            var request = Titanium.Network.createHTTPClient();

            request.open("POST","http://*********/sendToken.php");  
            var params = {  
                "token": e.deviceToken,
                "username": authProperties[0].username,
                "userId": authProperties[0].userId    
            };  

            request.send(params);

            Ti.API.info("Push notification types:         "+Titanium.Network.remoteNotificationTypes);  
    Ti.API.info("Push notification enabled:"+Titanium.Network.remoteNotificationsEnabled);  
},  
error:function(e){
    alert("Error during registration: "+e.error);

    Ti.API.info("Error during registration: "+e.error);  
},
callback:function(e)  
{  
    // called when a push notification is received.  
    //Titanium.Media.vibrate();  
    var data = JSON.parse(e.data);

    request.open("POST","http://*********/callback.php");  
    var params = {  
        "token": e.deviceToken,
        "username": authProperties[0].username,
        "userId": authProperties[0].userId    
    };  

    request.send(params);

    //  Message data for the inbox
    var inboxData = data.inbox;     

    Titanium.App.properties.setString("badgeCount",data.badge);

    var badge = data.badge;  
    if(badge > 0){  
        Titanium.UI.iPhone.appBadge = 202;//badge;  
    }  

    var message = data.message;
    if(message != ''){  
        var my_alert=Ti.UI.createAlertDialog({title:'',message:JSON.stringify(inboxData) });

        my_alert.show();  
    }  
}  
});

The following script handles the php part of the push notification:

$serverId = "81273";  
    $name = "APNS";  
    $apnsPort = 2195;//5223;  
    $passPhrase = "";  
    $fwrite = "";  
    $sslUrl = "ssl://gateway.push.apple.com:" . $apnsPort;  
    $apnsCert = "./apns-distr.pem";//give the apns.pem file path on your server  
    $badge = 22;
$message = "[". date("d-m-Y h:i:s") . '] Er is een nieuw bericht voor u.';  
$inboxArray = array();
$inboxArray["id"]= 1;
$inboxArray["message"] = "Dit bericht dient als test";
$inboxArray["date"] = date("d-m-Y h:i:s");
$apnspayload['aps'] = array ('alert' => $message,'badge' => $badge,'sound' => 'default', 'inbox' => $inboxArray);  

$payload = json_encode($apnspayload);  

$tokens = array();
$tokens[] = "********** ** * * *";

foreach($tokens as $tokenId){


    $apnsMessage = chr(1) . pack('N', time()) . pack('N', time() + 86400) . chr(0) . chr(32) 
        . pack('H*', str_replace(' ', '', $tokenId)) . chr(0) . chr(strlen($payload)) . $payload;  

    $streamContext = stream_context_create();  

    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);  
    stream_context_set_option($streamContext, 'ssl', 'passphrase', $passPhrase);  

    $apns = stream_socket_client($sslUrl, $error, $errorString, 6, STREAM_CLIENT_CONNECT, $streamContext);  

    if($apns){  
        $fwrite = fwrite($apns, $apnsMessage);  

        fclose($apns);  
        @socket_close($apns);  
    }else{  
        echo 'request failed';  
    }  
}`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:30:26+00:00Added an answer on June 17, 2026 at 2:30 pm

    Problem solved,

    It seems something with the JSON went wrong, still not sure what.

    In the App.js:
    var data = JSON.parse(e.data); upon removing the JSON.parse() the code worked.
    For some reason the JSON data did not need to be parsed.. thus the line became var data = e.data;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question earlier: How to get delta between two text items But
I asked this question earlier. I am intrigued by std::set but I have another
I asked this question over in the actual tutorial, but not sure I'll get
I know this question has been asked here before, but I don't think those
I know this question has been asked before, but none of the existing SO
This question has been asked many times before, but they all seem to relate
I'm sorry if this question has been asked. I have looked but can not
I know this question has been asked previously, but they were asked a long
I have asked this question on superuser as well, but have not yet gotten
I know that this question had been asked many times, but every answer seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.