Closed hulk374 closed 4 years ago
NSObject+AvoidCrash.m中把相应代码修改如下即可。『当方法已找到时,不需要做任何处理』。
(NSMethodSignature *)avoidCrashMethodSignatureForSelector:(SEL)aSelector {
NSMethodSignature *ms = [self avoidCrashMethodSignatureForSelector:aSelector];
BOOL flag = NO; if (ms == nil) { for (NSString classStr in noneSelClassStrings) { if ([self isKindOfClass:NSClassFromString(classStr)]) { ms = [AvoidCrashStubProxy instanceMethodSignatureForSelector:@selector(proxyMethod)]; flag = YES; break; } } if (flag == NO) { NSString selfClass = NSStringFromClass([self class]); for (NSString *classStrPrefix in noneSelClassStringPrefixs) { if ([selfClass hasPrefix:classStrPrefix]) { ms = [AvoidCrashStubProxy instanceMethodSignatureForSelector:@selector(proxyMethod)]; } } } } return ms; }
厉害了,正解。。。
NSObject+AvoidCrash.m中把相应代码修改如下即可。『当方法已找到时,不需要做任何处理』。
- (NSMethodSignature )avoidCrashMethodSignatureForSelector:(SEL)aSelector { NSMethodSignature ms = [self avoidCrashMethodSignatureForSelector:aSelector]; BOOL flag = NO; if (ms == nil) { for (NSString classStr in noneSelClassStrings) { if ([self isKindOfClass:NSClassFromString(classStr)]) { ms = [AvoidCrashStubProxy instanceMethodSignatureForSelector:@selector(proxyMethod)]; flag = YES; break; } } if (flag == NO) { NSString selfClass = NSStringFromClass([self class]); for (NSString *classStrPrefix in noneSelClassStringPrefixs) { if ([selfClass hasPrefix:classStrPrefix]) { ms = [AvoidCrashStubProxy instanceMethodSignatureForSelector:@selector(proxyMethod)]; } } } } return ms; }厉害了,正解。。。放在括号里面,读了一下,刚开始也纳闷为啥ms!=nil时,还去转发。。。懵逼一下午。。。
你好作者,我这还会出现楼主出现的问题 用的版本是已经跟1楼说的那种方法一样的了,求解决
作者你好,情况如下: 添加防止unrecognized selector sent to instance导致崩溃的类前缀 NSArray *noneSelClassPrefix = @[ @"LY", ]; [AvoidCrash setupNoneSelClassStringPrefixsArr:noneSelClassPrefix];
如果在 前缀为LY 的一个控制器中, 去调用系统的相册方法,那么会产生崩溃的,但iOS 9是没问题的. UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = NO; [self presentViewController:picker animated:YES completion:nil];
报错内容是 'NSInvalidArgumentException', reason: '-[NSInvocation setArgument:atIndex:]: index (2) out of bounds [-1, 1]' *** First throw call stack: (0x182956364 0x181b9c528 0x18283c130 0x18c1b05b4 0x18c1b3800 0x18c1b3d34 0x18c1b3750 0x18bf15388 0x10107b5f0 0x18be6c6b4 0x18be6c634 0x18be571dc 0x18be6bf28 0x18be6ba48 0x18be66f60 0x18be37f64 0x18c78d31c 0x18c78f8a8 0x18c7887c0 0x1828fe97c 0x1828fe8fc 0x1828fe184 0x1828fbd5c 0x18281be58 0x1846c8f84 0x18be9b67c 0x10107b74c 0x18233856c) libc++abi.dylib: terminating with uncaught exception of type NSException
调起相册会出现崩溃,但是相机是没问题的,通讯录也是会产生崩溃的. 希望作者优化一下.