当iOS上的phonegap应用在后台时,哔声不工作 [英] Beep not working when phonegap app is in background on iOS

查看:262
本文介绍了当iOS上的phonegap应用在后台时,哔声不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS版本的基于phonegap的导航应用程序。我的应用程序使用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和iOS 6.3.1的最新SDK

  • / www root 中的a href =http://docs.phonegap.com/en/2.5.0/cordova_notification_notification.md.html#notification.beep =nofollow> beep.wav li>
  • 我的应用程式的.plist设定「位置」和「音频」的「UIBackgroundModes」

  • 我的config.xml包含设定:



    < plugin name =Notificationvalue =CDVNotification/>



    < plugin name =Media value =CDVSound/>



    < preference name =MediaPlaybackRequiresUserActionvalue =false/>



    < preference name =AllowInlineMediaPlaybackvalue =true/>




如何解决这个问题:)

解决方案

如果有人感兴趣, / p>

我更新了本地通知 phonegap插件用于Cordova 2.x.我使用插件提供背景哔声和phonegap的前台哔声通过放置相同的声音为phonegap在www / as beep.wav为iOS项目中的本地通知资源as beep.caf。

  function doBeep(){
cordova.require('cordova / plugin / localnotification')。add(
function
console.log(Successfully added local notification);
},
function(){
console.error(Error added local notification);
},{
date:new Date(new Date()。getTime()),
repeat:'',
message:'',//没有消息所以只是beep
hasAction:true,
badge:0,
id:'1',
background:'background',
foreground:'running',
sound: beep.caf'
}
);
}

function running(){
console.log(在前台运行所以使用phonegap通知);
navigator.notification.beep();
}

function background(){
console.log(在后台运行,以便使用iOS本地通知);
}


I’m working on the iOS version of my phonegap-based navigation app. My app tracks the user’s location around a walk route using GPS and alerts the user using audio (navigator.notification.beep) and tactile (navigator.notification.vibrate) feedback when they reach a location at which there’s new instructions for them to follow.

When my app is running in the foreground, both the audible beep and the vibration fire on reaching the geographic location but when the app is paused in the background, either by pressing the power button to turn the screen off or pressing the home button to return to the springboard, only the vibration works - the beep is not audible. I’ve added debug so I can see in the log file that the app is calling navigator.notification.beep() while in the background but the beep sound isn't made. I’ve tested my app on an iPhone 4S running iOS 6.3.1 and iPad 2 running iOS 5.1.1. Obviously the iPad doesn’t vibrate but the beep works while the app is in the foreground but not when in the background.

  • My app is using Phonegap 2.5.0
  • I’m using latest Xcode v4.6.2 with latest SDK for iOS 6.3.1
  • I’m using a beep.wav in the /www root
  • My app’s .plist sets "UIBackgroundModes" of "location" and "audio"
  • My config.xml contains the settings:

    <plugin name="Notification" value="CDVNotification" />

    <plugin name="Media" value="CDVSound" />

    <preference name="MediaPlaybackRequiresUserAction" value="false" />

    <preference name="AllowInlineMediaPlayback" value="true" />

Any suggestions how to fix this would be most appreciated :-)

解决方案

In case anyone else in interested, here’s how I solved this:

I updated the Local Notifications phonegap plugin for use with Cordova 2.x. I used the plugin to provide the background beep and phonegap for the foreground beep by placing the same sound for phonegap in www/ as beep.wav as for the local notification in the iOS project Resources as 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");
}

这篇关于当iOS上的phonegap应用在后台时,哔声不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆