googlesamples / ios-nearby

69 stars 30 forks source link

Nearby API causes crashes in app #42

Open pepejeria opened 4 years ago

pepejeria commented 4 years ago

The latest version 1.1.1 is causing crashes:

Crashed: com.apple.main-thread
0  SocialSteps                    0x1045ee490 __38-[GNSAudioBroadcastingOperation start]_block_invoke + 70 (GNSAudioModem.m:70)
1  SocialSteps                    0x1045f33e0 __42-[GNSAudioPlayer createAndStartAudioQueue]_block_invoke + 208 (GNSAudioPlayer.mm:208)
2  libdispatch.dylib              0x214558a38 _dispatch_call_block_and_release + 24
3  libdispatch.dylib              0x2145597d4 _dispatch_client_callout + 16
4  libdispatch.dylib              0x2145399e4 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 1008
5  CoreFoundation                 0x214aac32c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
6  CoreFoundation                 0x214aa7264 __CFRunLoopRun + 1924
7  CoreFoundation                 0x214aa67c0 CFRunLoopRunSpecific + 436
8  GraphicsServices               0x216ca779c GSEventRunModal + 104
9  UIKitCore                      0x241571c38 UIApplicationMain + 212
10 SocialSteps                    0x104557a3c main + 18 (NumberFormatter+Custom.swift:18)
11 libdyld.dylib                  0x21456a8e0 start + 4

Device states: 100% background

I am not sure if this is the correct place to report bugs, but I couldn't find anywhere else.

robertmryan commented 4 years ago

@pepejeria - I’m getting a similar error. Did you figure out the source of this problem?

pepejeria commented 4 years ago

Hi @robertmryan,

sadly not, it seems like the library is crashing for some reason. I see this crash from time to time in the crash logs, but not a blocker since it happens in the background.

robertmryan commented 4 years ago

I’m guessing that it’s because I’ve requested both BLE and microphone, but the background documentation says:

Background operations must use the BLE medium only; audio is not supported.

This crash, which as you say, is happening only when the app is in the background, is happening in GNSAudioBroadcastingOperation. I’m going to try turning off microphone access when it goes into background, and back on when it comes back to foreground.

robertmryan commented 4 years ago

So far that solution seems promising...

pepejeria commented 4 years ago

@robertmryan Did it work? What exactly did you do?

trancee commented 3 years ago

@robertmryan @pepejeria Any possible workaround code you could share here?

robertmryan commented 3 years ago

So, I have a property for the mediums:


#if targetEnvironment(simulator)
private var mediums: GNSDiscoveryMediums = [.audio]
#else
private var mediums: GNSDiscoveryMediums = [.audio, .BLE]
#endif

And in applicationWillResignActive I just will remove .audio:

params.strategy = GNSStrategy { [weak self] params in
    guard
        let params = params,
        let self = self
    else { return }

    params.allowInBackground = background
    var mediums = self.mediums
    if background {
        mediums.remove(.audio)
    }
    params.discoveryMediums = mediums
}
trancee commented 3 years ago

That's great, thank you for sharing!