我想在我的apple watchOS应用程序中访问实时心率.在主题演讲中,他们强调开发人员现在可以访问实时数据.但我在文档中找不到任何相关内容.
有人对我有暗示吗?
我正在WatchOS上构建一个非常简单的锻炼应用程序:其中一个功能是在训练期间提供音频反馈.我可以在显示器打开时播放文件,但是当显示器很暗时,手表不会播放我的文件.
有人可以查看我的快速代码并帮助我弄清楚我错过了什么吗?
这是我的extensionDelegate.swift:
var audioPlayer = AVAudioPlayer()
class ExtensionDelegate: NSObject, WKExtensionDelegate {
func applicationDidFinishLaunching() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryAmbient, with: .duckOthers)
} catch {
print("audiosession cannot be set")
}
do { try audioSession.setActive(true) }
catch {
print ("audiosession cannot be activated")
}
let test = URL(fileURLWithPath: Bundle.main.path(forResource: "1", ofType: "m4a")!)
try! audioPlayer = AVAudioPlayer(contentsOf: test)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
func applicationDidBecomeActive() {
// Restart any tasks that were paused (or not yet started) while the application was …Run Code Online (Sandbox Code Playgroud)