What should be the appropriate system flow for functionality of the push-notification service that is developed using PHP and Pushwoosh? -
i'm php developer profession. so, don't have knowledge mobile apps, ios, android, etc. such things. so, please try understand me.
i've app developed using ios respective development team. now, have provide app push-notifications using pushwoosh.
i've understood mean push-notification , usage of pushwoosh same. also, i'm able send sample push-notification using app_id , auth_key got pushwoosh control panel. when run corresponding php file server 'success message' proper status code receive.
my query how implement push-notifications service app server side perspective?
now let's consider more dynamic , practical thing.
actually there 1 table in mysql database contains notifications. new entry gets inserted table i've check whether it(notification) logged-in user or not. if there is/are new notifications generated logged in user i've send push-notification concerned user his/her respective device through 'pushwoosh'.
now question should php file contains code checking new notifications , sending push-notifications called app side or there other way around?
in other words doubt should check new notifications should performed upon request coming app?
i discussed same issue mobile app development team, told me don't send kind of request have send push-notification. told me meaning of push-notification same app never send request server, server should send notification app whenever available.
then in case how should php file contains code should execute since there no request received it?
another question here if app not going send request php file how should know user logged in , requesting new notifications generated him/her, if any?
suppose, if request has come php file should need make token based authentication in php code particular user or done on app side , upon validating user send request php file?
also check new notifications should make every 2 minutes interval(polling). check should made? mean php file receive request app every 2 minutes or what?
please me resolving these tedious issues.
thanks.
following sample code (the auth token , app id have been changed 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 above code i'm going integrate code checking , sending new notifications if available.
lets begin installation of ios app. ios team should take care register device after installation apple push notification server (apns) , push token.
on login should send push token php server , server should take care store along user's data. typically (but not obligatory) after successful login server should generate unique token , send device used afterwards communication between them. if there no expiration requirements, token enough know user logged in.
if expiration required server should save time stamp of moment when token generated , store db. requires update time stamp whenever user interacts app / server.
a cron job set run on every 2 minutes call php script. php script goes through table in db , checks new notifications , if finds such, should try send push notification. if 'is logged in' check required, script should check user's token , on success should send /createmessage
api request pushwoosh corresponding device push token. parameter in json request should similar this:
"devices":["dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41"]
note can add here 1000 push tokens.
this way send push notification concrete user's device.
please note here, 1 user install app on multiple devices. in case push tokens should stored , used when sending push notification.
i hope didn't miss something.
Comments
Post a Comment