我正在尝试为我的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/
目录下的自定义音频。
sound_danger.caf
)放置在platforms/ios
中,但它不起作用。服务器发送了"ios": { "sound": "sound_danger.caf" }
但是播放的是默认声音。你知道错在哪里吗? - 27leaves