1
我有一個watchOS應用程序,通過從iPhone父應用程序請求當前的音量:AVAudioSession總是返回相同的outputVolume
session?.sendMessage(["getVolume":1], replyHandler: {
replyDict in
if let currentVolume = replyDict["currentVolume"] as? Float{
NSLog("Current volume received from phone with value: \(currentVolume)")
}
}, errorHandler: {
(error) -> Void in
NSLog("Error: :\(error)")
// iOS app failed to get message. Send it in the background
//self.session?.transferUserInfo(["getVolume":1])
})
的iPhone應用程序,處理這樣的:
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
NSLog("Received a message")
if let _ = message["getVolume"] as? Int{
replyHandler(["currentVolume":AVAudioSession.sharedInstance().outputVolume])
}
else{
replyHandler([:])
}
}
這始終返回與第一次請求相同的outputVolume。
我調查了幾件事情,如是否有某種緩存的背景請求,但它總是一個新的調用,返回新值。
是否有任何解決方法以不同的方式獲取系統音量或解決方案如何使其與AVAudioSession
一起工作?
這有從其他應用程序的任何音頻靜音其缺點是不是我打算做 – arnoapp
@ AzzUrr1設置音頻會話類別不會干擾任何其他正在播放的音頻。 – JAL
這工作!謝謝!還需要添加音頻背景模式 – arnoapp