Search code examples
objective-cios6mfixcode4.5nscondition

EAAcessory errors while closing session with iOS 6.0 GM


There is a MFI device that is connected to iPhone 4S (6.0 GM) or to iPad (6.0 GM) via Bluetooth (2.1 + EDR). The project was built on Xcode 4.5 GM. When the app gets EAAccessoryDidDisconnectNotification it will send message [_eaSessionController closeSession];. All these worked nice in iOS 5.1.1 or earler. But on iOS6 with this message I got logs as follows:

-[NSCondition dealloc]: condition (<NSCondition: 0x2e5640> '(null)') deallocated while still in use
Break on _NSLockError() to debug.

Any ideas?


Solution

  • There is no such trouble in iOS 6.1+. To fix this for iOS 6.0 and iOS 6.0.1 please use next solution:

    Please note: this is only temp solution allow your users with iOS 6.0 and 6.0.1 continue use your app.

    There is a simple hack to avoid application crashes: just create new category and override dealloc method (NSCondition) for iOS 6.0 and iOS 6.0.1:

    #import "NSCondition+LeakDealloc.h"
    #import <objc/runtime.h>
    
    @implementation NSCondition (LeakDealloc)
    
    - (void) safeDealloc
    {
        float sVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
        if (sVersion < 6.0 || sVersion >= 6.1)
        {
            [self safeDealloc];
        }
    }
    
    + (void) load 
    {
        method_exchangeImplementations(class_getInstanceMethod(self, @selector(dealloc)), class_getInstanceMethod(self, @selector(safeDealloc)));
    }
    
    @end
    

    This solution make new leak, after 20 min tests and about 50 BG/FG swithces instruments shows 10 NSCondition leaks (960 Bytes), BUT no one crash!