转自:http://blog.itpub.net/12231606/viewspace-1081952/

今天将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


纠结了好久,定位代码错误位置如下:

  1. NSString *retString = [network SendData:url data:requestDictionary];
  2. NSError *error = nil;
  3. NSDictionary *retDictionary = [ NSDictionary dictionaryWithJSONString:retString error:&error];
  4. if(!error)
  5. {
  6. ret.flag = [[retDictionary objectForKey:@\"flag\" ] intValue];
  7. ret.msg = [retDictionary objectForKey:@\"msg\"];
  8. }
  9. return ret;
  10. }

推断原因是:NSDictionary 是内嵌对象,但是dictionaryWithJSONString  另一个自定义对象的方法。为什么要用与NSDictionary  相同的名称,原因就是要返回NSDictionary 对象。

自定义对象代码如下:

  1. @implementation NSDictionary (NSDictionary_JSONExtensions)
  2. + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError
  3. {
  4. return([[CJSONDeserializer deserializer] deserialize:inData error:outError]);
  5. }
  6. + (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;
  7. {
  8. NSData *theData = [inJSON dataUsingEncoding:NSUTF8StringEncoding];
  9. return([self dictionaryWithJSONData:theData error:outError]);
  10. }
  11. @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的更多相关文章

  1. iOS - error:unrecognized selector sent to class 导入第三方SDK .a后不识别,运行崩溃

    今天将app统计的.a静态库包含到一个app应用中,调试时报下面的错误: *** Terminating app due to uncaught exception 'NSInvalidArgumen ...

  2. Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'

    下面是iOS开发用第三方库可能出现的错误,及其解决方法: 1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstra ...

  3. IOS 错误 [UIWebView cut:]: unrecognized selector sent to instance

    那在什么场景中会出现这种情况呢? 如果一个包含文字的输入元素有焦点,然后按钮的点击会导致输入失去焦点,然后接下来在输入时双按会重新得到焦点并从弹出bar中选择剪切复制粘贴,就会导致此error. 也就 ...

  4. IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0'

    开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [7661:2826851] *** Terminating app due t ...

  5. iOS 程序报错:reason: [NSArrayI addObject:]: unrecognized selector sent to instance

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI ad ...

  6. ios unrecognized selector sent to instance出现的原因和解决方案

    概述:造成unrecognized selector sent to instance iphone,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对 ...

  7. iOS开发——异常:[__NSCFNumber length]: unrecognized selector sent to instance

      *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumbe ...

  8. iOS [AFHTTPSessionManager GET:parameters:progress:success:failure:]: unrecognized selector sent to

    AFN更新到4.0.1后,崩溃[AFHTTPSessionManager GET:parameters:progress:success:failure:]: unrecognized selecto ...

  9. '-[__NSCFString stringFromMD5]: unrecognized selector sent to instance 0x14d89a50'

    类型:ios 问题描述: 导入百度地图 然后在模拟器运行可以,真机测试不行: 报错: '-[__NSCFString stringFromMD5]: unrecognized selector sen ...

随机推荐

  1. 20181023-4 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 01

    作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2383] 版本控制:[https://git.coding.net/lglr2 ...

  2. Android开发随笔2

    昨天:对anroid的系统架构了解比如:基于linux内核,整合库函数和java编译器并且为上层提供封装好的api和一些基本系统级应用 创建一个安卓的模拟器 了解了ddms的作用和内容 利用已有的工具 ...

  3. 在windows和unbuntu上安装octave

    windows安装octave 安装wiki Octave ftp库 从上述的库中可以找到对应的版本的octave的exe安装程序,或者是zip等的压缩包,建议直接下载对应系统的exe执行文件.安装. ...

  4. 第5章 Linux 常用网络指令

    网络参数设定使用的指令 手动/自动设定与启动/关闭 IP 参数: ifconfig, ifup, ifdown ifconfig :查询.设定网络卡与 IP 网域等相关参数:ifup, ifdown: ...

  5. Spring+Netty4实现的简单通信框架

    参考:http://cpjsjxy.iteye.com/blog/1587601 Spring+Netty4实现的简单通信框架,支持Socket.HTTP.WebSocket_Text.WebSock ...

  6. css3 伪元素 ::before ::after

    键代码分析: /*css代码*/ .effect::before, .effect::after{ content:""; position:absolute; z-index:- ...

  7. (五)hadoop系列之__集群搭建SSH无密访问多台机器

    免密码ssh设置 现在确认能否不输入口令就用ssh登录localhost: $ ssh localhost 如果不输入口令就无法用ssh登陆localhost,执行下面的命令: . 并修改hosts映 ...

  8. 使用vue-cli3新建一个项目,并写好基本配置

    1. 使用vue-cli3新建项目: https://cli.vuejs.org/zh/guide/creating-a-project.html 注意,我这里用gitbash不好选择选项,我就用了基 ...

  9. Linux下启用MySQL慢查询

    MySQL在linux系统中的配置文件一般是my.cnf找到[mysqld]下面加上log-slow-queries=/data/mysqldata/slowquery.loglong_query_t ...

  10. python的N个小功能之正则匹配

    1.. 匹配任意除换行符“\n”外的字符:2.*表示匹配前一个字符0次或无限次:3.+或*后跟?表示非贪婪匹配,即尽可能少的匹配,如*?重复任意次,但尽可能少重复,惰性匹配:4. .*? 表示匹配任意 ...