I have never dwelled in to node.js however I have now had to, to be able to implement push notifications in my iPhone app.
I have successfully created a node script that successfully pushes apple notifications to mobile devices.
I can run the script via ssh, and it works fine.
I created a php script with the following code...
<?php
$output = shell_exec("/home1/devjustin/nodejs/bin/node /home1/devjustin/apns/index.js 2>&1");
print_r ($output);
?>
Now here is my problem...
If I run that php script via my browser, I do not get a notification pop up on my phone. The php script does infact interact with the node script, but it seems to fail towards the very end of the node script, without any explanation at all, without any errors being displayed.
If I run the php script in ssh via, php mobile-push.php
, it works as I had hoped it would, and I get a notification pop up on my phone.
So, after days, and I mean literally days, I have not been able to find a solution.
I was wondering if perhaps it was my host. I am currently running a shared server through hostgator, although it seems like all the permissions I required, are there and active.
Any help would be super appreciated. If you want me to provide examples, I am happy to.
I need this feature in my app, so that when an action is performed, and uploaded to my server, I can trigger push notifications to users who the uploaded data affects.
P.S: I created some console.log lines in my node script, and they all show up when running the php script through my browser, except for the console prints surrounding the following segment of my node script:
// index.js
// Actually send the notification
apnProvider.send(notification, deviceToken).then(function(result) {
console.log(result);
});
Regards,
Justin.
regards to below discussion with edwin:
console - starting
console - tokens set...
console - second last stage
console for apnProvider - EventEmitter {
client:
Client {
config:
{ token: [Object],
ca: null,
passphrase: null,
production: false,
address: 'api.development.push.apple.com',
port: 443,
rejectUnauthorized: true,
connectionRetryLimit: 10,
heartBeat: 60000 },
endpointManager:
EventEmitter {
domain: null,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_endpoints: [],
_endpointIndex: 0,
_config: [Object],
_connectionFailures: 0 },
queue: [] },
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined }
//notification console output
{ encoding: 'utf8',
payload: { id: 123 },
compiled: false,
aps:
{ badge: 3,
sound: 'ping.aiff',
alert:
{ body: '[Cancelled] Friday, 4th of August at 3:00PM.',
title: 'Business Name' } },
expiry: 1501839082,
priority: 10,
topic: 'com.mybundleid.mybundleid' }
I have ran an strace on the script through php, and this is the break point. Could someone please help me understand this?
console - tokens set...
console - second last stage
open("/proc/meminfo", O_RDONLY|O_CLOEXEC) = 10 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=26871, si_uid=638} --- +++ killed by SIGABRT +++
This error was in relation to the permissions that were being granted to the web user. The only way I would have been able to completely execute the remainder of the code in my file would have been to grant root access, or above web user level privileges.
Since that was not an option I was ready to use, I have instead scrapped the node script, and rewritten the entire push sending notification system in php, using these three links that I found here on SO as my resources (incase anyone else needs assistance with the server side sending).
Sending multiple iphone push notifications + APNS + PHP + Tutorial
Generate .pem file Used to setup Apple PUSH Notification
APNS PHP JSON Payload structure
I can now send push notifications automatically through my app by accessing a php script. This way, with some additional php, users will now be able to interact with each other through apples push notifications whilst in app, or on the web platform.
Regards,
Justin.