Background text for speech on iOS

I read a lot of articles, read a lot of StackOverflow posts and tried different solutions, but I can't get it to work.

For an application that communicates with Bluetooth headsets, the user must be able to start / stop the stopwatch when the user presses a button on the headset. When this button is pressed, I get a bluetooth event and start a stopwatch (receiving this bluetooth event in the background is not a problem). When the stopwatch is running, I use the AVSpeechSynthesizer to say the text "Stopwatch is running." Now my problem arises: I want to write text every minute, talking about the number of minutes that have passed. But also when the application is in the background ...

I read about solutions like:

 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) 

It really worked, but I can not find anything about how stable this code is for production (when the application is downloaded from the App Store). Also, scheduled local notifications cannot run any code when the application is in the background. Even the postUtteranceDelay of AVSpeechUtterance seems unstable. I set the property to 460 seconds, but the text was spoken after a random 56 seconds ...

I have turned on almost all the background modes for my application.

 <key>UIBackgroundModes</key> <array> <string>audio</string> <string>bluetooth-central</string> <string>fetch</string> <string>remote-notification</string> </array> 

Other people suggest making a quiet soundtrack. But it seems that applications using such "silent traces" are abandoning the Apple Review team.

What depresses me the most is that applications like Runkeeper and Seconds Interval Timer can do this. Even when I turn on airplane mode and turn off all settings (e.g. push, motion sensing) from applications. So why can't I find a working solution ...?

Does anyone have a suggestion where to start?

+5
source share

Source: https://habr.com/ru/post/1275317/


All Articles