Skip to content

Commit

Permalink
Bug fix for issue CocoaLumberjack#6 - crash in registered dynamic log…
Browse files Browse the repository at this point in the history
…ging on iOS when voice over is enabled. Special thanks to carpeaqua for the patch
  • Loading branch information
robbiehanson committed Sep 5, 2011
1 parent 21dc793 commit 400829c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Lumberjack/DDLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,50 @@ + (BOOL)isRegisteredClass:(Class)class
SEL getterSel = @selector(ddLogLevel);
SEL setterSel = @selector(ddSetLogLevel:);

#if TARGET_OS_IPHONE

// Issue #6 - Crashes on iOS 4.2.1 and iPhone 4
//
// Crash caused by class_getClassMethod(2).
//
// "It's a bug with UIAccessibilitySafeCategory__NSObject so it didn't pop up until
// users had VoiceOver enabled [...]. I was able to work around it by searching the
// result of class_copyMethodList() instead of calling class_getClassMethod()"

unsigned int methodCount, i;
Method *methodList = class_copyMethodList(object_getClass(class), &methodCount);

if (methodList != NULL)
{
BOOL getterFound = NO;
BOOL setterFound = NO;

for (i = 0; i < methodCount; ++i)
{
SEL currentSel = method_getName(methodList[i]);

if (currentSel == getterSel)
{
getterFound = YES;
}
else if (currentSel == setterSel)
{
setterFound = YES;
}

if (getterFound && setterFound)
{
return YES;
}
}

free(methodList);
}

return NO;

#else

Method getter = class_getClassMethod(class, getterSel);
Method setter = class_getClassMethod(class, setterSel);

Expand All @@ -548,6 +592,8 @@ + (BOOL)isRegisteredClass:(Class)class
}

return NO;

#endif
}

+ (NSArray *)registeredClasses
Expand Down

0 comments on commit 400829c

Please sign in to comment.