在我的应用程序中,我需要在后台或屏幕锁定时更新位置。当用户接近某个指定位置(警报位置)时,app会发出声音通知。当他们接近时,app会发出一声嘟嘟声,下一声嘟嘟声两次,下一次嘟嘟声三次。
我知道如何在后台更新位置,但我在声音警报方面有困难。我使用AudioServicesPlaySystemSound的音频会话
do {
let audioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayback)
try audioSession.setActive(true)
} catch {
print("session does not init")
}
/* *** */
AudioServicesPlaySystemSound(beepSound)我的算法如下:当找到最近的警报位置时,应用程序会播放嘟嘟声。
它在前台工作,但在锁定屏幕下不能。
发布于 2016-05-26 15:33:33
您需要在锁定屏幕下允许通知,并且需要向用户请求权限。在AppDelegate的application函数中添加以下内容
let notificationCategory = UIMutableUserNotificationCategory()
let categories = Set<UIUserNotificationCategory>(arrayLiteral: notificationCategory)
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
application.registerUserNotificationSettings(settings)https://stackoverflow.com/questions/37454124
复制相似问题