今天學(xué)(踩)到了一個(gè) iOS 開發(fā)小知識(shí)(坑):如果靜態(tài)庫里定義了 Category荣德,那使用這個(gè)靜態(tài)庫的 App 工程里闷煤,OtherLinker Flags 還需要加上 -ObjC 這個(gè)參數(shù)涮瞻,否則 Category 定義的方法會(huì)找不到鲤拿。
此事緣起于對(duì) WebRTC iOS 靜態(tài)庫的使用署咽,運(yùn)行時(shí)報(bào)錯(cuò) '+[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 如果需要加載進(jìn)來需要告訴 other linker flags參數(shù) -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.