0

我正在使用 Swift 来使用 Google Nearby Messages 库。我按照示例代码设置库。我正在使用蓝牙和麦克风来测试功能。我在 viewDidDisappear() 中释放了发布/订阅。基本上它是两行代码:

publication = nil
subscription = nil

但是,当我关闭视图控制器时,有时整个应用程序会崩溃。堆栈跟踪仅显示崩溃与音频有关。这是堆栈跟踪的一部分:

Crashed: AudioRecorderCallbackQueue
0  libdispatch.dylib              0x18df39f60 _dispatch_barrier_sync_f_slow + 596 

1  ProjectLibs                    0x1037ad8e0 std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >::vector(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) + 2808

2  ProjectLibs                    0x1037ad8e0 std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >::vector(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) + 2808

3  ProjectLibs                    0x1037ad0f4 std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >::vector(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) + 780

4  libsystem_blocks.dylib         0x18df7ea28 _Block_release + 144

有谁知道可能导致崩溃的原因,以及如何解决它或防止应用程序崩溃?

谢谢!

4

1 回答 1

0

我设置了一个应用程序以按照您描述的工作方式运行。通过启用日志记录,我注意到它仍会在短时间内发送消息,这可能是您崩溃的原因。

您可以使用以下命令启用日志记录:

GNSMessageManager.setDebugLoggingEnabled(true)

通过在流程的早期将它们设置为 nil,我能够让它们在视图控制器完全关闭之前停止发送。

以下内容会尽快完成(甚至在 viewWillDisappear 之前):

override func willMove(toParentViewController parent: UIViewController?) {
    super.willMove(toParentViewController: parent)

    if parent == nil {
        publication = nil
        subscription = nil
    }
}
于 2016-12-01T19:33:16.960 回答