【问题标题】:Beep not working when phonegap app is in background on iOS当 phonegap 应用程序在 iOS 上处于后台时,哔声不起作用
【发布时间】:2013-05-20 01:59:58
【问题描述】:

我正在开发基于 phonegap 的导航应用的 iOS 版本。我的应用程序使用 GPS 跟踪用户在步行路线周围的位置,并在用户到达有新指示要遵循的位置时使用音频 (navigator.notification.beep) 和触觉 (navigator.notification.vibrate) 反馈提醒用户。

当我的应用程序在前台运行时,到达地理位置时会发出哔哔声和振动,但当应用程序在后台暂停时,可以通过按电源按钮关闭屏幕或按主页按钮返回跳板,只有振动起作用 - 听不到哔哔声。我添加了调试,因此我可以在日志文件中看到应用程序在后台调用 navigator.notification.beep() 但没有发出哔声。我在运行 iOS 6.3.1 的 iPhone 4S 和运行 iOS 5.1.1 的 iPad 2 上测试了我的应用程序。显然 iPad 不会振动,但当应用程序在前台时会发出哔声,但在后台时不会。

  • 我的应用正在使用 Phonegap 2.5.0
  • 我正在使用最新的 Xcode v4.6.2 和最新的 SDK for iOS 6.3.1
  • 我在 /www 根目录中使用 beep.wav
  • 我的应用程序的 .plist 设置了“位置”和“音频”的“UIBackgroundModes”
  • 我的 config.xml 包含设置:

任何解决此问题的建议将不胜感激:-)

【问题讨论】:

    标签: ios geolocation notifications cordova background-process


    【解决方案1】:

    如果其他人有兴趣,这是我解决这个问题的方法:

    我更新了 Local Notifications phonegap 插件以用于 Cordova 2.x。我使用该插件来提供背景哔声和前景哔声的 phonegap,方法是在 www/ 中将 phonegap 的声音设置为 beep.wav,并将 iOS 项目 Resources 中的本地通知设置为 beep.caf。

    function doBeep(){
      cordova.require('cordova/plugin/localnotification').add(
        function(){
          console.log("Successfully added local notification");
        },
        function(){
          console.error("Error adding local notification");
        },{
          date: new Date(new Date().getTime()),
          repeat:'',
          message: '', // No message so just beep
          hasAction: true,
          badge: 0,
          id: '1',
          background:'background',
          foreground:'running',
          sound: 'beep.caf'
        }
      );
    }
    
    function running(){
      console.log("Running in the foreground so use a phonegap notification");
      navigator.notification.beep();
    }
    
    function background(){
      console.log("Running in the background so an iOS local notification will be used");
    }
    

    【讨论】:

    • 您是否有机会发布测试接近度(“当他们到达某个位置时”)条件测试的代码?
    • 当然,我可以做到,但我如何做到这一点有点复杂:由于 GPS 波动,实际测试导致我使用受约束的横向距离计算。也许作为一个新问题发布,发布/发送一个链接然后我可以回答它?那么它不会隐藏在这个问题下,其他人可以找到它...... :-)
    • fusion27:我回答了你的问题here +1 将不胜感激 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2019-01-04
    • 1970-01-01
    • 2018-08-03
    • 2021-11-28
    相关资源
    最近更新 更多