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

KVO registers twice #77

Closed haifengkao closed 10 years ago

haifengkao commented 10 years ago

When I was testing my app's stability in poor network condition, I got the following app crash report. The crash is caused by SFObservers (https://github.com/krzysztofzablocki/SFObservers) because it detects the same keypath is registered by [LARSAdController startAdNetworkAdapterClass:] twice.

I think LARSAdController should remove the existing observation before making a new one.

*** Assertion failure in -[TOLAdAdapteriAds addObserver:forKeyPath:options:context:], /Users/SFObservers/NSObject+SFObservers.m:106
2014-04-25 20:16:18.646 MyApp[36109:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You shouldn't register twice for same keyPath, context'
*** First throw call stack:
(
    0   CoreFoundation                      0x0539f1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x055f48e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0539f048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x02b524de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   MyApp                               0x00199210 -[NSObject(SFObservers) sf_addObserver:forKeyPath:options:context:] + 1072
    5   MyApp                               0x0043a246 -[LARSAdController startAdNetworkAdapterClass:] + 2854
    6   MyApp                               0x004396db -[LARSAdController startAdNetworkAdapterClassAtIndex:] + 539
    7   MyApp                               0x00437192 -[LARSAdController adFailedForNetworkAdapterClass:] + 418
    8   MyApp                               0x0043ccd8 -[TOLAdAdapterGoogleAds adView:didFailToReceiveAdWithError:] + 264
    9   MyApp                               0x003527cc __50-[GADDelegateManager didFailToReceiveAdWithError:]_block_invoke + 91
    10  MyApp                               0x0035209c GADDelegateManagerDispatchSynchronouslyOnMainThreadWithBlock + 50
    11  MyApp                               0x00352715 -[GADDelegateManager didFailToReceiveAdWithError:] + 422
    12  MyApp                               0x00350886 -[GADSlot didFailToReceiveAdWithError:] + 104
    13  MyApp                               0x0036057e -[GADAdFetcher resourceFailedToLoadWithError:] + 169
    14  MyApp                               0x00361198 -[GADAdFetcher connection:loadDidFail:httpStatusCode:] + 782
    15  MyApp                               0x00362a89 -[GADURLConnection connection:didFailWithError:] + 227
    16  Foundation                          0x02d3bbd7 ___NSURLConnectionDidFail_block_invoke + 134
    17  Foundation                          0x02cd27e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
    18  Foundation                          0x02b5af5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
    19  Foundation                          0x02b5aec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
    20  Foundation                          0x02cd294d -[NSURLConnectionInternal _withConnectionAndDelegate:] + 76
    21  Foundation                          0x02d3acfa _NSURLConnectionDidFail + 90
    22  CFNetwork                           0x01c32a61 ___ZN27URLConnectionClient_Classic17_delegate_didFailEP9__CFErrorU13block_pointerFvvE_block_invoke + 142
    23  CFNetwork                           0x01c303de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
    24  CoreFoundation                      0x05340c69 CFArrayApplyFunction + 57
    25  CFNetwork                           0x01b99441 _ZN19RunloopBlockContext7performEv + 155
    26  CFNetwork                           0x01c7b3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
    27  CFNetwork                           0x01b99257 _ZN17MultiplexerSource7performEv + 299
    28  CFNetwork                           0x01b9906c _ZN17MultiplexerSource8_performEPv + 76
    29  CoreFoundation                      0x0532877f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    30  CoreFoundation                      0x0532810b __CFRunLoopDoSources0 + 235
    31  CoreFoundation                      0x053451ae __CFRunLoopRun + 910
    32  CoreFoundation                      0x053449d3 CFRunLoopRunSpecific + 467
    33  CoreFoundation                      0x053447eb CFRunLoopRunInMode + 123
    34  GraphicsServices                    0x067e35ee GSEventRunModal + 192
    35  GraphicsServices                    0x067e342b GSEventRun + 104
    36  UIKit                               0x03e86f9b UIApplicationMain + 1225
    37  MyApp                               0x00003490 main + 592
    38  libdyld.dylib                       0x05b17701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
haifengkao commented 10 years ago

the issue is caused by https://github.com/krzysztofzablocki/SFObservers.