I'm a PHP Developer by profession. So, I don't have much knowledge about mobile apps, iOS, Android, etc. such like things. So, please try to understand me.
I've an app developed using iOS by the respective development team. Now, I have to provide this app the Push-Notifications using Pushwoosh.
I've understood what is mean by push-notification and usage of Pushwoosh for the same. Also, I'm able to send sample push-notification by using the app_id and auth_key I got from Pushwoosh Control Panel. When I run the corresponding PHP file from the server the 'Success Message' with proper status code I receive.
My query is about actually how to implement this push-notifications service into the app from server side perspective?
Now for this let's consider the more dynamic and practical thing.
Actually there is one table in MySQL database which contains the notifications. As soon as any new entry gets inserted into that table I've to check whether it(notification) is for logged-in user or not. If there is/are any new notifications generated for logged in user I've to send the push-notification to the concerned user to his/her respective device through 'Pushwoosh'.
Now my question is should the PHP file which contains the code for checking the new notifications and sending it as a push-notifications be called from the app side or is there any other way around?
In other words my doubt is should this check for new notifications should be performed only upon a request coming from app?
I discussed the same issue with the mobile app development team, they told me we don't send you any kind of request you simply have to send us the push-notification. They told me the meaning of push-notification is only the same that app never send any request to the server, the server itself should send the notification to the app whenever available.
Then in this case how should the PHP file that contains the code should get execute since there is no request received for it?
Another question here is if the app is not going to send any request to the PHP file then how should I know which user is logged in and requesting for the new notifications generated for him/her, if any?
Suppose, if the request has come for the PHP file then should I need to make token based authentication in PHP code for that particular user or it will be done on app side and only upon validating the user successfully they will send the request to PHP file?
Also the check for new notifications should be make for every two minutes interval(polling). From where this check should be made? I mean will the PHP file receive request from app for every two minutes or what?
Please help me resolving these tedious issues.
Thanks.
Following is my sample code (The Auth Token and App ID have been changed for security purpose):
<?php
define('PW_AUTH', 'XXXXXXXXXXX');
define('PW_APPLICATION', 'XXXXXXXXXXX');
define('PW_DEBUG', true);
function pwCall($method, $data) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
}
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'test',
'data' => array('custom' => 'json data'),
'link' => 'http://pushwoosh.com/'
)
)
)
);
?>
In the above code only I'm going to integrate code for checking and sending new notifications if available.