New Ionic push registering device tokens -
i´ve set necessary push notifications described here.
i registering device on startup like:
// register pushio $ionicpush.register().then(function(t) { return $ionicpush.savetoken(t, {ignore_user:true}); }).then(function(t) { console.log('token saved:', t.token); });
the device token logged "token saved: xxxxthetokenxxxx".
now i´m sending push curl , ionic.io dashboard. status (checked curl) of message 200 , no errors. push notification sent:
{"meta": {"request_id": "8d9c69ce-b66c-4002-8cb3-f91c57505b0f", "version": "2.0.0-beta.0", "status": 200}, "data": []}
but device isn´t recieving notification. think due savetoken()
function. savetoken()
saving token?
does have clue how solve this?
update: i´m using code send push:
<?php $curl = curl_init(); $token = "mytoken"; curl_setopt_array($curl, array( curlopt_url => "https://api.ionic.io/push/notifications", curlopt_returntransfer => true, curlopt_encoding => "", curlopt_maxredirs => 10, curlopt_timeout => 30, curlopt_http_version => curl_http_version_1_1, curlopt_customrequest => "post", curlopt_postfields => ' { "tokens": "bbc654c496abc2dc42a40941ac944f0a8aeb0d5b227d523e335dbd51b71ed646", "profile": "getto", "notification": { "message": "hello world!" } }', curlopt_httpheader => array( "authorization: bearer $token", "content-type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "curl error #:" . $err; } else { echo $response; } ?>
edit: strange thing is, on android device token not registered.
initialize service , register device in module's run function. you'll need device token registered user sending notification user.
$ionicpush.init({ debug: true, onnotification: function (notification) { console.log('token:', notification.payload); }, onregister: function (token) { console.log('device token:', token); $ionicpush.savetoken(token); // persist token in ionic platform } }); $ionicpush.register();
ionic push lets create targeted push notifications through dashboard (ionic.io). can send notifications server in below format.
curl -x post -h "authorization: bearer api_token" -h "content-type: application/json" -d '{ "tokens": ["device_token"], "profile": "profile_tag", "notification": { "message": "hello world!" "android": { "title": "hi user", "message": "an update available app", "payload": { "update": true } } } }' "https://api.ionic.io/push/notifications"
Comments
Post a Comment