Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 新的离子推注册设备令牌_Ionic Framework_Push Notification - Fatal编程技术网

Ionic framework 新的离子推注册设备令牌

Ionic framework 新的离子推注册设备令牌,ionic-framework,push-notification,Ionic Framework,Push Notification,我已经设置了所有必要的推送通知 我正在启动时注册设备,如: // register for pushio $ionicPush.register().then(function(t) { return $ionicPush.saveToken(t, {ignore_user:true}); }).then(function(t) { console.log('Token saved:', t.token); }); 设备令牌记录为“令牌已保存:x

我已经设置了所有必要的推送通知

我正在启动时注册设备,如:

// register for pushio
    $ionicPush.register().then(function(t) {
      return $ionicPush.saveToken(t, {ignore_user:true});
    }).then(function(t) {
      console.log('Token saved:', t.token);
    });
设备令牌记录为“令牌已保存:xxxxTheTokenxxx”

现在,我从CURL和爱奥尼亚·io仪表板发送push。消息的状态(用CURL检查)为200,没有错误。因此,将发送推送通知:

{"meta": {"request_id": "8d9c69ce-b66c-4002-8cb3-f91c57505b0f", "version": "2.0.0-beta.0", "status": 200}, "data": []}
但是我的设备没有收到通知。我认为这是由于
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;
} ?>

初始化服务并在模块的运行功能中注册设备。您需要由用户注册的设备令牌来向用户发送通知

$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();
Ionic Push允许您通过仪表板()创建目标推送通知。您还可以使用以下格式从服务器发送通知

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"

您不必在设备上保存令牌,您必须将其传递给API。这会将令牌保存到爱奥尼亚数据库!?当我从Ionic.io仪表板发送推送时,这个保存的令牌应该被传递到Ionic.io仪表板使用的API。我说得对吗?还是我需要自己保存代币?如果我在设备上尝试并向该令牌发送通知,则会显示上面的回复。但没有传递任何信息。我已经用我的代码更新了这个问题。谢谢但是代币保存在哪里呢?如何在curl中检索它们?我是否需要自己将令牌保存在外部数据库中?您可以随时使用针对单个用户的自定义消息向您的用户发送有针对性的通知。参考如果要执行上述任何操作,则必须根据所有用户在任何数据库中的唯一ID保存所有用户的令牌。但是,如果您的要求只是向所有用户发送批量通知,并且只能手动发送,那么您可以通过导航到Push›New notification在仪表板中创建通知。参考