今天学(踩)到了一个 iOS 开发小知识(坑):如果静态库里定义了 Category,那使用这个静态库的 App 工程里,OtherLinker Flags 还需要加上 -ObjC 这个参数,否则 Category 定义的方法会找不到。
此事缘起于对 WebRTC iOS 静态库的使用,运行时报错 '+[UIDevice deviceType]: unrecognized selector sent toclass 0x1b47d8c60'。
起先我没有尝试求助 Google,而是自己在琢磨,但无果。而 Google 很快给了我答案。所以遇到问题,先 Google 一下也没什么损失,说不定就有答案呢 :)
webrtc iOS native : +[UIDevice deviceType]: unrecognized selector sent toclass 0x3aa4b420
It turned out that this issue was caused by ldfalg "-force_load"option in my application. Changed it to "-ObjC" and it is workingfine now. Please refer to below for more information.
https://groups.google.com/d/msg/discuss-webrtc/G64eXgQh7Xs/eUMhSB8aCgAJ
+[UIDevice deviceType]: unrecognized selector sent to class 0x1a01696a8
webrtc 使用了category 如果需要加载进来需要告诉 other linker flags参数 -ObjC 或者-all_load
https://github.com/RTCat/rtcat_ios_demo3/issues/1
What does the -ObjC linker flag do?
This flag causes the linker to load every object file in the library thatdefines an Objective-C class or category. While this option will typicallyresult in a larger executable (due to additional object code loaded into theapplication), it will allow the successful creation of effective Objective-Cstatic libraries that contain categories on existing classes.
网友评论