最近公司也不知道从哪买的了一套,框架很老了,pod更新之后到处报错,解决报错问题,解决了很长时间,头疼,算了还是用原来项目也不更新框架了,跑起来再说。结果跑起来之后,随便点点都报错,报错信息如下: 本文借鉴他人,引用请标注出处
解决办法:可以把如下代码作为NSObject扩展类添加到项目中,引用即可。
比如创建一个NSObject的分类"ZSKJNSObject+NSObject.h"
#pragma mark - 这个方法解决到处崩溃的问题
+ (void)load{
SELoriginalSelector =@selector(doesNotRecognizeSelector:);
SELswizzledSelector =@selector(sw_doesNotRecognizeSelector:);
Method originalMethod = class_getClassMethod(self, originalSelector);
Method swizzledMethod = class_getClassMethod(self, swizzledSelector);
if(class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))){
class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}else{
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
+ (void)sw_doesNotRecognizeSelector:(SEL)aSelector{
//处理 _LSDefaults 崩溃问题
if([[selfdescription] isEqualToString:@"_LSDefaults"] && (aSelector ==@selector(sharedInstance))){
//冷处理...
return;
}
[selfsw_doesNotRecognizeSelector:aSelector];
}
网友评论