larsacus / LARSAdController

Lightweight ad mediation for iOS to properly manage multiple ad networks dynamically including iAd and Google ads.
http://theonlylars.com/blog/2013/01/10/stupid-easy-ads-with-larsadcontroller-3-dot-0/
MIT License
269 stars 60 forks source link

Constant KVO Crashes #104

Closed nahum365 closed 10 years ago

nahum365 commented 10 years ago

My app was just released on the App Store. Once it started to get downloads, I noticed a bunch of crashes related to LARSAdController. The app currently has around 75 users, 18 of those users have experienced this crash.

Some info:

This is the crash report:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x1000000c

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x363d9f46 objc_msgSend + 5
1  Foundation                     0x2984db0f NSKeyValuePushPendingNotificationPerThread + 226
2  Foundation                     0x2983e0fd NSKeyValueWillChange + 464
3  Foundation                     0x2982aed5 -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 172
4  Foundation                     0x2985e205 _NSSetCharValueAndNotify + 76
5  umusio                         0x000711c5 -[LARSAdController observeValueForKeyPath:ofObject:change:context:] (LARSAdController.m:687)
6  Foundation                     0x2983eb43 NSKeyValueNotifyObserver + 262
7  Foundation                     0x2983e7ef NSKeyValueDidChange + 346
8  Foundation                     0x2982b011 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 88
9  umusio                         0x000700cd -[LARSAdController animateBannerForAdapterHidden:withCompletion:] (LARSAdController.m:433)
10 umusio                         0x0006f83d -[LARSAdController adFailedForNetworkAdapterClass:] (LARSAdController.m:337)
11 umusio                         0x00029795 -[TOLAdAdapteriAds bannerView:didFailToReceiveAdWithError:] (TOLAdAdapteriAds.m:132)
12 iAd                            0x2cb8acd3 -[ADBannerView _forwardErrorToDelegate:] + 254
13 iAd                            0x2cb8a5a7 -[ADBannerView serverBannerViewDidFailToReceiveAdWithError:] + 146
14 libdispatch.dylib              0x3692d7bb _dispatch_call_block_and_release + 10
15 libdispatch.dylib              0x3692d7a7 _dispatch_client_callout + 22
16 libdispatch.dylib              0x36930fa3 _dispatch_main_queue_callback_4CF + 718
17 CoreFoundation                 0x28bac9d1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
18 CoreFoundation                 0x28bab0d1 __CFRunLoopRun + 1512
19 CoreFoundation                 0x28af9211 CFRunLoopRunSpecific + 476
20 CoreFoundation                 0x28af9023 CFRunLoopRunInMode + 106
21 GraphicsServices               0x2fef20a9 GSEventRunModal + 136
22 UIKit                          0x2c1051d1 UIApplicationMain + 1440
23 umusio                         0x0009c3b7 main (main.m:16)
larsacus commented 10 years ago

What version of the CocoaPod are you using?

nahum365 commented 10 years ago

I installed it manually.

enmiller commented 10 years ago

For the manual install, are you using the latest files?

nahum365 commented 10 years ago

I implemented LARSAdController about 2 weeks ago. Have there have been any updates since then?

nahum365 commented 10 years ago

OK I just switched over to Cocoapods to see if it would somehow fix the issue. Nope. Any ideas?

larsacus commented 10 years ago

No, switching to cocoa pods wouldn't just fix the issue since we haven't pushed any code in a month or so.

Are you using KVO anywhere else in your app, or any other third party libraries that relate to KVO in some strange way? The above crash report indicates some kind of memory issue, but you say you are getting it every single time. Is this only on iOS 8? On the simulator or device? Can you send a sample project that reproduces the crash, or does the crash go away in a sample project?

nahum365 commented 10 years ago

The crash doesn't always happen, it just happens a lot. I guess it definitely could be an issue with another library that uses KVO. I'll check that when I get home. Is there a way I could prevent the crash, though?=

larsacus commented 10 years ago

We have to find what's causing the crash before we can work around it.

nahum365 commented 10 years ago

I believe I found the issue. I commented out the dealloc line in my view controller, so the KVO observers weren't getting removed, causing the crash.

Now that everything is working correctly, is it ok if I ask here why my ads disappear after about 10 seconds?

larsacus commented 10 years ago

You shouldn't have to do any cleanup or anything with the ad controller. It manages everything itself under the hood. So it's surprising that something in your view controller was causing it to crash on something internally...

nahum365 commented 10 years ago

I had my view controllers registering for KVO on the adVisible property so that I could manage content insets for table views. It's working well right now as far as I can tell, but the ads disappear after 10 seconds or so and don't reappear until the app is relaunched...

larsacus commented 10 years ago

Since you're on the latest codebase, you can use the delegation pattern on LARSAdController rather than KVO -- which may be less prone to the problems that can come with using KVO.

@property (nonatomic, weak) id<LARSBannerVisibilityDelegate> delegate;
nahum365 commented 10 years ago

I switched to the delegate and everything is working fine now. Thanks for the help!