PostHog / posthog-ios

PostHog iOS SDK
https://posthog.com/docs/libraries/ios
MIT License
32 stars 41 forks source link

Crash when entering foreground #3

Closed joshkopecek closed 4 years ago

joshkopecek commented 4 years ago

Got a reproducible error with 1.0.2 when entering foreground after having backgrounded the app. Seems to be a similar problem with the selectors as the previous didFinishLaunching crash.

Here is the crashlog:

Last Exception Backtrace:
0   CoreFoundation                  0x1bca52a48 __exceptionPreprocess + 220 (NSException.m:199)
1   libobjc.A.dylib                 0x1bc779fa4 objc_exception_throw + 56 (objc-exception.mm:565)
2   CoreFoundation                  0x1bc9565a8 -[NSObject(NSObject) doesNotRecognizeSelector:] + 140 (NSObject.m:144)
3   CoreFoundation                  0x1bca56af4 ___forwarding___ + 1324 (NSForwarding.m:3514)
4   CoreFoundation                  0x1bca58a7c _CF_forwarding_prep_0 + 92
5   PostHog                         0x107f24cd8 -[PHGPostHogIntegration staticContext] + 1116 (PHGPostHogIntegration.m:51)
6   PostHog                         0x107f25024 -[PHGPostHogIntegration updateStaticContext] + 28 (PHGPostHogIntegration.m:198)
7   CoreFoundation                  0x1bc9ae288 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:787)
8   CoreFoundation                  0x1bc9ae2d0 ___CFXRegistrationPost1_block_invoke + 64 (CFNotificationCenter.c:175)
9   CoreFoundation                  0x1bc9ad630 _CFXRegistrationPost1 + 368 (CFNotificationCenter.c:198)
10  CoreFoundation                  0x1bc9ad2e8 ___CFXNotificationPost_block_invoke + 104 (CFNotificationCenter.c:1371)
11  CoreFoundation                  0x1bc92959c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1416 (CFXNotificationRegistrarOld.m:168)
12  CoreFoundation                  0x1bc9acc38 _CFXNotificationPost + 1244 (CFNotificationCenter.c:1359)
13  Foundation                      0x1bcd090c8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60 (NSNotification.m:576)
14  UIKitCore                       0x1c0aee2a4 -[UIApplication _sendWillEnterForegroundCallbacks] + 280 (UIApplication.m:10519)

…
mariusandra commented 4 years ago

Hi @joshkopecek , very strange. If I try to background/foreground the app (CocoaPodsExample in the posthog-ios repo), everything works fine.

screencast 2020-05-20 16-48-48

How can I reproduce this? Can you show the exact line in posthog where the crash happens? I fixed another bug in the iOS library today and added a few things, so it might be worth upgrading to 1.0.3 as well just in case.

joshkopecek commented 4 years ago

Just tried with v1.0.3. I get a fault with isAdvertisingCapturingEnabled when returning to foreground (action as above).

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ASIdentifierManager isAdvertisingCapturingEnabled]: unrecognized selector sent to instance 0x2826a7170'

Which is in PHPPostHogIntegration.m

mariusandra commented 4 years ago

Hi @joshkopecek , thanks for that! I think I found and fixed the bug. Could you test if with 1.0.4 everything works?

joshkopecek commented 4 years ago

@mariusandra yes, that works! Nice work. I haven't got any more crashes, going to push this out in our app now. 🤞

mariusandra commented 4 years ago

Great! If you have any other issues or feedback, don't hesitate to share them :)