m1c*_*rdy 11 push-notification ionic-framework
从来就成立了所有必要的描述推送通知这里.
我在启动时注册设备,如:
// register for pushio
$ionicPush.register().then(function(t) {
return $ionicPush.saveToken(t, {ignore_user:true});
}).then(function(t) {
console.log('Token saved:', t.token);
});
Run Code Online (Sandbox Code Playgroud)
设备令牌被记录为"令牌已保存:xxxxthetokenxxxx".
现在我从CURL和Ionic.io仪表板发送推送.消息的状态(使用CURL检查)为200且没有错误.所以推送通知发送:
{"meta": {"request_id": "8d9c69ce-b66c-4002-8cb3-f91c57505b0f", "version": "2.0.0-beta.0", "status": 200}, "data": []}
Run Code Online (Sandbox Code Playgroud)
但我的设备没有收到通知.我认为这是由于saveToken()功能.saveToken()保存令牌的位置在哪里?
有没有人知道如何解决这个问题?
更新:我使用此代码发送推送:
<?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;
} ?>
Run Code Online (Sandbox Code Playgroud)
编辑:奇怪的是,在Android上,设备令牌未注册.
初始化服务并在模块的运行函数中注册您的设备。您将需要用户注册的设备令牌才能向用户发送通知。
$ionicPush.init({
debug: true,
onNotification: function (notification) {
console.log('token:', notification.payload);
},
onRegister: function (token) {
console.log('Device Token:', token);
$ionicPush.saveToken(token); // persist the token in the Ionic Platform
}
});
$ionicPush.register();
Run Code Online (Sandbox Code Playgroud)
Ionic Push 允许您通过仪表板 ( ionic.io ) 创建有针对性的推送通知。您还可以按以下格式从服务器发送通知。
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 is available for your App",
"payload": {
"update": true
}
}
} }' "https://api.ionic.io/push/notifications"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1306 次 |
| 最近记录: |