iOS - error:unrecognized selector sent to class 导入第三方SDK .a后不识别,运行崩溃
今天将app统计的.a静态库包含到一个app应用中,调试时报下面的错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithJSONString:error:]:unrecognized selector sent to class 0x235e7ec'
unrecognized selector sent to class 0x235e7ec'
*** First throw call stack:
(
0 CoreFoundation 0x022195e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01f288b6 objc_exception_throw + 44
2 CoreFoundation 0x022b67a3 +[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0220990b ___forwarding___ + 1019
4 CoreFoundation 0x022094ee _CF_forwarding_prep_0 + 14
...
10 Foundation 0x01b80597 -[NSThread main] + 76
11 Foundation 0x01b804f6 __NSThread__main__ + 1275
12 libsystem_c.dylib 0x02d625b7 _pthread_start + 344
13 libsystem_c.dylib 0x02d4cdce thread_start + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException
纠结了好久,定位代码错误位置如下:
- NSString *retString = [network SendData:url data:requestDictionary];
- NSError *error = nil;
- NSDictionary *retDictionary = [ NSDictionary dictionaryWithJSONString:retString error:&error];
- if(!error)
- {
- ret.flag = [[retDictionary objectForKey:@\"flag\" ] intValue];
- ret.msg = [retDictionary objectForKey:@\"msg\"];
- }
- return ret;
- }
推断原因是:NSDictionary 是内嵌对象,但是dictionaryWithJSONString 另一个自定义对象的方法。为什么要用与NSDictionary 相同的名称,原因就是要返回NSDictionary对象。
自定义对象代码如下:
- @implementation NSDictionary (NSDictionary_JSONExtensions)
- + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError
- {
- return([[CJSONDeserializer deserializer] deserialize:inData error:outError]);
- }
- + (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;
- {
- NSData *theData = [inJSON dataUsingEncoding:NSUTF8StringEncoding];
- return([self dictionaryWithJSONData:theData error:outError]);
- }
- @end
所以,推断xcode没有正确解析代码,把dictionaryWithJSONString 方法错误认为是内嵌对象NSDictionary 的内部方法,但NSDictionary 没有这个方法,所以调试的时候,就找不到该方法的实现,报出错误信息:unrecognized selector sent to class 0x235e7ec'
推断出问题的可能原因后,很有可能是工程的setting信息有问题。于是开始一个一个参数过,一开始以为是Search Paths的各种路径配置错误,后来验证不是。否则编译都应该过不去。
于是,将范围定在Build Settings下的Linking的参数列表。马上有一个参数映入眼帘:Other Linker Flags,没有设置。通过google,查询相关说明:
-all_load Loads all members of static archive libraries.
-ObjC Loads all members of static archive libraries that implement an Objective-C class or category.
-force_load (path_to_archive) Loads all members of the specified static archive library. Note: -all_load forces all members of all archives to be loaded. This option allows you to target a specific archive.
翻译过来就是-all_load就是会加载静态库文件中的所有成员,-ObjC就是会加载静态库文件中实现一个类或者分类的所有成员,-force_load(包的路径)就是会加载指定路径的静态库文件中的所有成员。所以对于使用runtime时候的反射调用的方法应该使用这三个中的一个进行link,以保证所有的类都可以加载到内存中供程序动态调用
到这里,基本就明白了,就是这个参数没有设置的原因。将Other Linker Flags=-ObjC,再重新调试,运行成功!!
iOS - error:unrecognized selector sent to class 导入第三方SDK .a后不识别,运行崩溃的更多相关文章
- Unity导出xcode后自动化导入第三方SDK
最近因为在给项目接入第三方SDK,遇到了一个比较烦人的事情就是,每次出包都要重新根据第三方SDK说明设置xcode,每次最少花20分钟来设置,如果出错的话就不一定是20分钟的事了,所以我决定要做一个自 ...
- 解决:导入第三方jar包后,仍然出现java.lang.NoClassDefFoundError的错误
最近,在运行某个Android工程的时候,一直抛出java.lang.NoClassDefFoundError异常. 按照异常所给出的信息,应该是程序使用到的第三方jar包出了问题. 但是,这些第三方 ...
- (转)ios error:unrecognized selector sent to class
转自:http://blog.itpub.net/12231606/viewspace-1081952/ 今天将app统计的.a静态库包含到一个app应用中,调试时报下面的错误: *** Termin ...
- unity 引入 ios 第三方sdk
原地址:http://blog.csdn.net/u012085988/article/details/17785023 unity开发中ios应用时,要想成功引入第三方sdk,首先得知道c#与obj ...
- Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'
下面是iOS开发用第三方库可能出现的错误,及其解决方法: 1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstra ...
- IOS 错误 [UIWebView cut:]: unrecognized selector sent to instance
那在什么场景中会出现这种情况呢? 如果一个包含文字的输入元素有焦点,然后按钮的点击会导致输入失去焦点,然后接下来在输入时双按会重新得到焦点并从弹出bar中选择剪切复制粘贴,就会导致此error. 也就 ...
- IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0'
开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [7661:2826851] *** Terminating app due t ...
- iOS 程序报错:reason: [NSArrayI addObject:]: unrecognized selector sent to instance
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI ad ...
- ios unrecognized selector sent to instance出现的原因和解决方案
概述:造成unrecognized selector sent to instance iphone,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对 ...
随机推荐
- GitHub上优秀的开源资源
(1)整理了所有跟编程相关的免费书籍 https://github.com/EbookFoundation/free-programming-books/blob/master/free-progra ...
- 【Java】Spring之Resource(三)
Java的各种URL前缀的标准类和标准处理程序不足以完全访问低级资源.例如,没有URL可用于访问需要从类路径或相对于a获取的资源的标准化实现 ServletContext.虽然可以为专用URL 前缀注 ...
- CGI = MCC + MNC + LAC + CI
CGI = MCC + MNC + LAC + CI 摘自:http://www.360doc.com/content/19/0801/10/65611272_852334484.shtml CGI是 ...
- intellij maven配置与使用
目录 intellij maven配置与使用 Maven 常用设置介绍 Maven 骨架创建 Java Web 项目 Maven 组件来管理项目 @(目录) intellij maven配置与使用 M ...
- Python - Django - JsonResponse 对象
用 json 模块和 HttpResponse 返回生成的 json views.py: from django.shortcuts import render, HttpResponse impor ...
- 改进初学者的PID-介绍
最近看到了Brett Beauregard发表的有关PID的系列文章,感觉对于理解PID算法很有帮助,于是将系列文章翻译过来!在自我提高的过程中,也希望对同道中人有所帮助.作者Brett Beaure ...
- 【DeepCTR】
DeepFM: https://www.jianshu.com/p/6f1c2643d31b CCPM,FGCNN: https://cloud.tencent.com/developer/artic ...
- MockMvc 进行 controller层单元测试 事务自动回滚 完整实例
package com.ieou.ms_backend.controller; import com.google.gson.Gson; import com.ieou.ms_backend.dto. ...
- 记录 centos samba 安装
https://www.ruletree.club/archives/4/ https://www.linuxidc.com/Linux/2017-03/141390.htm
- `GLIBCXX_3.4.15' not found when using mex file in matlab (linux)
from: http://www.360doc.com/content/14/0314/16/175261_360565922.shtml Invalid MEX-file '*/*/*.mexa64 ...