简体   繁体   English

在iOS上的Cordova Phonegap本地通知声音

[英]Cordova Phonegap local notification sound on iOS

I'm trying to test the local notifications on iOS using Cordova. 我正在尝试使用Cordova测试iOS上的本地通知。

Everything it's working fine except the sound, I only get the default notification sound, not the custom sound I've added in the options. 除了声音之外,它的工作正常,我只得到默认的通知声音,而不是我在选项中添加的自定义声音。

This is only happening on iOS . 这只发生在iOS上

Code: 码:

var now = new Date().getTime(),
    _10_seconds_from_now = new Date(now + 3*1000);

window.plugin.notification.local.add({
            id:      1,
            title:   'Reminder',
            message: 'Dont forget to buy some flowers.',
            repeat:  'weekly',
            date:    _10_seconds_from_now,
            sound:  'www/alarms/burglar.caf'
});

Okay, after a few looks in the objective-c code I finally made it work! 好吧,在看了几个Objective-c代码之后我终于成功了!

The solution it's very simple, but not documented anywhere. 解决方案很简单,但没有记录在任何地方。 You have to put the prefix file:// and all will work. 您必须添加前缀file://,所有文件都可以使用。 sound: 'file://alarms/factory.wav' 声音:“ file://alarms/factory.wav”

Example: 例:

window.plugin.notification.local.add({
            id:      2,
            title:   'Reminder',
            message: 'Dont forget to buy some flowers blah blah blah.',
            repeat:  'weekly',
            date:    _10_seconds_from_now,
            sound:  'file://alarms/factory.wav'
        });

API says: API说:

Notification sound on iOS iOS上的通知声音

Note: Custom sounds must be under 30 seconds when played. 注意:自定义声音播放时必须在30秒以内。 If a custom sound is over that limit, the default system sound is played instead. 如果自定义声音超过该限制,则会播放默认的系统声音。

This selected answer suggested: 选定的答案建议:

From the Cordova Docs : 来自Cordova Docs

  • Cordova implements beep by playing an audio file via the media API. Cordova通过媒体API播放音频文件来实现蜂鸣声。
  • The user must provide a file with the desired beep tone. 用户必须提供具有所需蜂鸣音的文件。
  • This file must be less than 30 seconds long, located in the www/ root, and must be named beep.wav 此文件的长度必须小于30秒,位于www/ root中,并且必须命名为beep.wav

I also faced that problem you can use this code as i applied and it's working fine for me 我也遇到了这个问题,您可以在我申请时使用此代码,它对我来说很好

cordova local notification sound not working in ios and andorid 科尔多瓦本地通知声音在iOS和Andorid中不起作用

open the link I think it will help to you 打开链接我认为它会对你有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM