背景文本到iOS上的演讲

Jan*_*bos 5 text-to-speech background-process ios swift

我阅读了很多文章,阅读了许多StackOverflow帖子并尝试了不同的解决方案,但我无法让它发挥作用.

对于与蓝牙耳机通信的应用程序,用户必须能够在用户按下耳机上的按钮时启动/停止秒表.按下此按钮时,我收到一个蓝牙事件并启动秒表(在后台接收此蓝牙事件不是问题).秒表启动后,我用它AVSpeechSynthesizer来说"秒表开始".现在出现了我的问题:我希望每分钟都有一个文本到演讲,说出已经过去的分钟数.但是当应用程序在后台时......

我读过这样的解决方案:

var bgTask = UIBackgroundTaskIdentifier()
bgTask = UIApplication.shared.beginBackgroundTask(expirationHandler: {
   UIApplication.shared.endBackgroundTask(bgTask)
})
let timer = Timer.scheduledTimer(timeInterval: 60.0, target: self, selector: #selector(notificationReceived), userInfo: nil, repeats: true)
RunLoop.current.add(timer, forMode: RunLoopMode.defaultRunLoopMode)
Run Code Online (Sandbox Code Playgroud)

它确实有效,但我找不到任何关于此代码在生产中的稳定性(从App Store下载应用程序时).当应用程序在后台时,计划的本地通知也无法触发任何代码.即使是财产postUtteranceDelayAVSpeechUtterance似乎不太稳定.我将属性设置为460秒,但是文本在随机56秒后被说出......

我为我的应用程序打开了几乎所有的后台模式.

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>bluetooth-central</string>
    <string>fetch</string>
    <string>remote-notification</string>
</array>
Run Code Online (Sandbox Code Playgroud)

其他人建议制作一个无声的音轨.但似乎使用那种"无声轨道"的应用程序被Apple Review团队拒绝了.

令我印象最深刻的是,像Runkeeper和Seconds Interval Timer这样的应用程序可以完成他的工作.即使我打开飞行模式并禁用应用程序中的所有设置(如推动,动作感应).那么,为什么我找不到可行的解决方案......?

有没有人有建议从哪里开始?