Android 使用离子推送通知的自定义声音

Android 使用离子推送通知的自定义声音,android,ios,cordova,ionic-framework,phonegap-pushplugin,Android,Ios,Cordova,Ionic Framework,Phonegap Pushplugin,我正在尝试在Ionic应用程序中为推送通知实现自定义声音。 我将声音文件复制到www/上,并设置插件选项,如下所示 //In app.run $ionicPush.init({ "debug": true, "onNotification": function(notification){ $cordovaDialogs.alert(notification.message, 'Notification', 'OK').then(function(){

我正在尝试在Ionic应用程序中为推送通知实现自定义声音。 我将声音文件复制到www/上,并设置插件选项,如下所示

//In app.run
$ionicPush.init({
      "debug": true,
      "onNotification": function(notification){
        $cordovaDialogs.alert(notification.message, 'Notification', 'OK').then(function(){
          console.log(notification);
        });
      }
      "onRegister": function(data) {
        console.info("New device registered with token "+data.token);
      }
      "pluginConfig": {
        "ios": {
          "badge": true,
          "sound": true
         },
         "android": {
           "iconColor": "#343434"
         }
      }
      });

//In my main controller - 
  $scope.saveUserDeviceReg = function(data){
    var ionicUser = Ionic.User.current();
    if(!ionicUser.id){
      ionicUser.id = $scope.user.userId;
    }
    ionicUser.set('name', $scope.user.name);
    ionicUser.set('image', $scope.user.profilePic);
    ionicUser.set('email', $scope.user.email);
    $ionicPush.addTokenToUser(ionicUser);
    ionicUser.save();
    if($scope.user.devices){
      $scope.user.devices[data.token] = true;
      $scope.user.$save().then(function(success){
        console.log("User device saved");
      },function(error){
        console.error("Error saving user device");
      });
    }
    else{
      var devices = {};
      devices[data.token] = true;
      $scope.user.devices = devices;
      $scope.user.$save().then(function(success){
        console.log("User device updated");
      },function(error){
        console.error("Error updating user device");
      });
    }
  };
​
  $ionicPush.register($scope.saveUserDeviceReg);
我从node.js服务器发送推送通知

  request({
            url: "https://push.ionic.io/api/v1/push",
            method: "POST",
            json: true,
            body: {
                "tokens":tokens,
                "notification": {
                    "alert": message.from + " : '" + message.text
                }
            },
            headers: {
                'Authorization': 'Basic ' + btoa(IONIC_PRIVATE_API_KEY + ":"),
                'X-Ionic-Application-Id': IONIC_APP_ID
            }
        }, function (error, response, body) {
            console.log(body);
        });

我想播放存储在
www/

中的自定义音频。使用Cordova CLI 7,您可以使用资源标签将声音复制到项目中

对于Android:

<resource-file src="sound.mp3" target="res/wav/sound.mp3" />

对于iOS:

<resource-file src="sub.caf"/>

旧答案:

要播放自定义声音,必须在推送通知数据上从服务器传递声音文件名

在iOS上,声音文件必须在应用程序项目上,而不是在www上

在android上,声音文件必须在
res/raw
文件夹中,而不是在www上


所以在iOS上,我把我的文件(
sound\u danger.caf
)放在
platforms/iOS
中,但它不起作用。服务器发送
“ios”:{“sound”:“sound\u danger.caf”}
,但它播放默认声音。你知道错在哪里吗?你必须把它放在xcode项目中,打开.xcodeproj并将声音拖到其中,或者使用钩子复制声音,或者使用一个自定义插件,只使用一个资源文件标签复制声音。在爱奥尼亚构建中,平台文件夹中没有res/raw。你可能指的是实际安装的android文件夹的res/raw吗?但是有一个res文件夹,对吗?您可以在res中创建原始文件夹folder@Sunil喇嘛,不知什么原因,我的声音没有发生。根据上面的答案,我假设声音应该进入的文件夹的完整路径是:platforms/android/res/raw。这是真的吗?谢谢