0

I'm using Swift to use Google Nearby Messages library. I followed the sample code to setup the library. I'm using both bluetooth and microphone to test the function. I dealloc the publication/subscription in viewDidDisappear(). Basically it's two lines of code:

publication = nil
subscription = nil

However, when I dismiss the view controller, sometimes the whole app will crash. The stacktrace only shows that the crash has something to do with the audio. Here's part of the stacktrace:

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

Does anyone have any idea what may have caused the crash, and how to solve it or prevent the app from crash?

Thanks!

  • Have you tried to set the message manager to nil as well? – CodeBender Nov 30 '16 at 23:07
  • @CodeBender Tried but it still crashes – Elsie Yunying Tu Dec 01 '16 at 01:39
  • Elsie, which version of Nearby Messages are you using? And which version of iOS? – Dan Webb Dec 01 '16 at 18:38
  • @DanWebb Hi we're using Nearby Messages 1.0.1, iOS 10.1.1. I find that it's much harder to crash the app on iOS9 devices, but I'm not sure if the iOS version is really a reason that causes the crash. – Elsie Yunying Tu Dec 01 '16 at 19:23
  • Elsie, trying upgrading to [Nearby Messages 1.1.0](https://cocoapods.org/pods/NearbyMessages#changelog). We fixed an audio crash bug in that release. Let me know if this resolves the problem. And apologies for the crash in the first place! – Dan Webb Dec 01 '16 at 19:58

1 Answers1

0

I set up an app to behave the way you have described yours as working. By enabling the logging, I notice that it is still sending messages for a brief period of time, which is likely where your crash is coming from.

You can enable logging with this command:

GNSMessageManager.setDebugLoggingEnabled(true)

By setting them to nil earlier in the process, I was able to get them to stop being sent before the viewcontroller was completely closed down.

The following does it at the soonest point possible (even before viewWillDisappear):

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

    if parent == nil {
        publication = nil
        subscription = nil
    }
}
CodeBender
  • 35,668
  • 12
  • 125
  • 132