首页 文章

在电话呼叫期间处理中断 - “开始”有效,但“结束”没有

提问于
浏览
4

该应用程序记录音频,并应在中断(例如电话呼叫)时停止录制音频,然后在电话呼叫结束时恢复录制音频 .

该应用程序当前在有电话时注册,但是当我挂断电话时,该应用程序不会注册中断已经结束 . (我没有打开其他应用程序) .

带功能代表

请参阅我的ViewController中的以下代码 .

func audioRecorderBeginInterruption(recorder: AVAudioRecorder){
    print("* * * * * * * inside begin interruption")}

func audioRecorderEndInterruption(recorder: AVAudioRecorder, withFlags flags: Int) {
    // THIS NEVER PRINTS, EVEN WHEN PHONE IS HUNG UP
    print("* * * * * * * inside end interruption")
}

有通知

我也尝试过处理通知中断,但是.Ended仍未处理,除非我接到电话而拒绝通话 . 请参阅我的AppDelegate中的代码

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        let center = NSNotificationCenter.defaultCenter()

        center.addObserver(self,
            selector:"sessionInterrupted:",
            name:AVAudioSessionInterruptionNotification,
            object:AVAudioSession.sharedInstance()) //self.myViewController.audioSession)


        return true
    }



 func sessionInterrupted(notification: NSNotification){
                if let typeValue = notification.userInfo?[AVAudioSessionInterruptionTypeKey] as? NSNumber{
                    if let type = AVAudioSessionInterruptionType(rawValue: typeValue.unsignedLongValue){
                        if type == .Began{
                            print("interruption: began")
                        } else{
                            // THIS ALSO NEVER PRINTS
                            print("interruption: ended")
                        }
        }

相关解决方案对我不起作用

当前假设

我目前的假设是,“结束”中断仅用于中断,例如当您接到电话时,您拒绝接听电话,但不是因为如果您实际接听电话,请稍微说话,然后挂机 . 我的猜测是没有办法在不使用越狱手机的情况下检测后一种情况 .

在这里以更广泛的方式扩展:iOS AVAudioSession interruption notification not working as expected

这个假设似乎在_2918582中得到了验证:

一次只有一个应用程序可以控制音频 . 如果DropVox正在录制并且另一个应用程序获得控制权,则称为“中断” . 当中断结束时,DropVox只有在前景7中才能恢复录制,这就是为什么我们警告不要使用“后台录制” “ 设置 .

我可以通过使用routing来检测正在使用的麦克风来处理中断 . 但我不认为我可以在后台重新激活录音,所以一旦应用程序回到前台,我就会这样做 .

是对的吗?

1 回答

  • -2

    DO NOT applicationWillResignActive:/applicationDidBecomeActive: 函数中的活动音频!

    当电话呼叫到达时,系统拥有音频,此时如果你在 applicationWillResignActive:/applicationDidBecomeActive: 功能中调用功能 [[AVAudioSession sharedInstance] setActive:YES error:&error] ,你的应用程序将拥有音频回传(实际上它应该是在通话时无法激活音频,但我不知道知道为什么它返回真实)并且不会收到结束中断 .

相关问题