記錄iOS踩的一些坑


總結以前碰到過的相關問題,記錄一波~


1. symbol(s) not found for architecture x86_64 編譯報錯,提示不支持x86_64

解決思路一: 排查一些庫文件或者代碼文件有沒有導入,一般為依賴文件找不到導致報錯, Build Phases -> complite sources 或者 link binary with libraries ,未添加的文件加進去,如果還是不行再試試其他問題

2. clang: error: no such file or directory: 'xxxx' (記錄於2019.03.06)

clang: error: no such file or directory: 'DACircularProgress'
clang: error: no such file or directory: 'MJRefresh'
clang: error: no such file or directory: 'YYImage'

編譯之后有以上報錯:
!. 檢查對應的目錄,是不是有沒刪除干凈的,紅色的文件
2. Other link flgs 設置不對, -framework和庫名是按順序成對出現的
如圖:

如果只刪除了庫名,沒有刪除庫名對應的-framework,那就是上述的報錯了
記錄一波,2019年03月06號 13:25:58

3. 項目中存在一些第三方庫的plist文件與系統的info.plist文件沖突 (刪掉即可)(記錄於2018.09.20)

Showing Recent Messages
:-1: Multiple commands produce '/Users/wangguibin/Library/Developer/Xcode/DerivedData/RongNiuOnline-fzkuntarvfnbhlahgftwzlapbewj/Build/Products/Debug-iphonesimulator/RongNiuOnline.app/Info.plist':
1) Target 'RongNiuOnline' (project 'RongNiuOnline') has copy command from '/Users/wangguibin/Desktop/MyFramework/RongNiuOnline/RongNiuOnline/AppConfigFile/Info.plist' to '/Users/wangguibin/Library/Developer/Xcode/DerivedData/RongNiuOnline-fzkuntarvfnbhlahgftwzlapbewj/Build/Products/Debug-iphonesimulator/RongNiuOnline.app/Info.plist'
2) Target 'RongNiuOnline' (project 'RongNiuOnline') has copy command from '/Users/wangguibin/Desktop/MyFramework/RongNiuOnline/RongNiuOnline/Common/Component/Other/FSCalendar/Info.plist' to '/Users/wangguibin/Library/Developer/Xcode/DerivedData/RongNiuOnline-fzkuntarvfnbhlahgftwzlapbewj/Build/Products/Debug-iphonesimulator/RongNiuOnline.app/Info.plist'
3) Target 'RongNiuOnline' (project 'RongNiuOnline') has process command with output '/Users/wangguibin/Library/Developer/Xcode/DerivedData/RongNiuOnline-fzkuntarvfnbhlahgftwzlapbewj/Build/Products/Debug-iphonesimulator/RongNiuOnline.app/Info.plist'

4. exception:*** Collection <__NSArrayM: 0x60400065e7e0> was mutated while being enumerated. (記錄於2018.01.30)

可變數組使用for-in方式遍歷,同時操作數據源數據產生的crash
正確✅姿勢應該使用enumerate-block或者使用局部變量中轉一下,操作完再賦值給全局變量

5. libc++abi.dylib: terminating with uncaught exception of type NSException

這個bug是XIB的View與控制器的命名很相似,比如 DemoView 和 DemoViewController ,系統讀取XIB文件的優先級也是先讀取控制器的,但是讀取View的時候發現它不是個View

6. error: cannot parse the debug map (記錄於2017.08.19)

引入了錯誤的頭文件或者是引入的是.m文件 排查到改掉即可

7. Xcode8.3.2使用UIImagePickerController導致[Generic] Creating an image format with an unknown type is an error (記錄於2017.08.09)

  1. 異步賦值
  2. dismiss的block里獲取image

8. 友盟統計報錯"_compress2", referenced from: (記錄於2017.06.20)

"_compress2", referenced from:

+[UMANUtil deflatedDataPrefixedWith:level:source:] in libMobClickLibrary.a(UMANUtil.o)

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

解決方法是:在Other Linker Flags里加入-lz然后再編譯通過

類似的其他

"_compress2", referenced from:

"_inflateReset", referenced from:

"_inflateInit_", referenced from:

"_inflateEnd", referenced from:

"_inflateInit2_", referenced from:

均可以通過-lz來解決。

-lz 會讓你的程序在編譯的時候against the built-in zlib,從而解決問題

9. WebView首次加載出現黑邊現象(記錄於2017.06.09)

需要設置如下類似代碼適配:(X以上設置88)
 _webView.scrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
[_webView.scrollView setContentOffset:CGPointMake(0, -64)];

 _webView.opaque = NO;
 _webView.backgroundColor = [UIColor whiteColor];
 

10. 遇到一個”libBacktraceRecording.dylib`__gcd_queue_item_enqueue_hook_block_invoke:”GCD崩潰的問題 (記錄於2017.05.17)

運行了好好的,過了大約幾分鍾之后自然crash... 百度google找了一些資料,說是這問題只出現在模擬器上.
解決辦法: 項目product > scheme > edit scheme > options > Queue Debugging: Enable backtrace recording 這個選項不要勾選☑️就ok啦(默認是勾選的 可能有的項目不會出現這個情況)

11. app:resource fork, Finder information, or similar detritus not al site:forums.developer.apple.com 爬坑 (記錄於2017.05.11)

  (1)關閉Xcode,打開終端;
(2)在終端中輸入cd(cd后跟一個空格,先不慌張按回車);
(3)打開項目的文件夾,文件夾中有四個文件(有的項目寫的比較亂,會有很多文件,這樣的就直接將項目文件拉到終端就行了),一個.md文件,一個.xcodeproj文件,一個工程文件和一個帶有Tests單詞的文件。將工程文件拉到終端中(知道路徑的可以在c的后面直接敲路徑),路徑會自動顯示出來,這時直接按回車鍵;
(4)輸入指令“xattr -rc .”,回車; (xattr -rc . 注意這個小點一定要打上)
(5)打開項目重新運行,OK了!

12. 低級錯誤❌, 復制粘貼或者因為粗心漏寫一些東西導致UI不呈現或者顯示錯亂等問題,歸納總結為可能存在以下原因:

  1. 數據源(數組或者字典等容器)未初始化
  2. 未設置代理,比如UITableView或者UICollectView
  3. 未添加到父視圖上或者未給定frame/約束布局
  4. 變量名寫錯成另一個控件的
  5. 寫之前要三思而后動,切不可操之過急~

13. Error installing libwebp, google的庫,pod默認是用的google的源,SDWebImage使用webP的時候需要依賴這個庫,目前就只有兩種方法可以解決:

  1. 掛代理(需要設置終端代理)
  2. 修改本地依賴文件libwebp.podspec.json 里的源的地址為github的鏡像地址 (不建議這么做,畢竟update repo之后又被覆蓋了)
[!] Error installing libwebp
[!] /usr/local/bin/git clone https://chromium.googlesource.com/webm/libwebp /var/folders/9d/jkc05y752h1csv8s91s27pg80000gn/T/d20170503-52118-q8kwcb --template= --single-branch --depth 1 --branch v0.5.1

Cloning into '/var/folders/9d/jkc05y752h1csv8s91s27pg80000gn/T/d20170503-52118-q8kwcb'...
fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/': Failed to connect to chromium.googlesource.com port 443: Operation timed out

14. ld: 2 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

創建了同名的文件,編譯沖突了

15. *** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3920.26.113/UICollectionView.m:2420

未注冊或者注冊時機不對

16. pod trunk push 失敗, 提示[!] You (xxxx@qq.com) are not allowed to push new versions for this pod. The owners of this pod are xxx153@gmail.com.

那是我之前用的別的郵箱注冊推送的,現在換號換電腦了,所以這樣提示,問題是我才是倉庫的所有者啊,我應該可以修改這個才對啊,搜索一番以后發現可以移除該倉庫的舊郵箱持有者或者添加新的持有者

#移除擁有者的郵箱
pod trunk remove-owner xxx.podspec xxxx@gmail.com
# 執行完🤩提示這個 我了個去
[!] No pod found with the specified name. 
#試圖添加擁有權限 
pod trunk add-owner LibName  xxxx@qq.com
#繼續報錯
[!] You are not allowed to add owners to this pod.
# 原來是之前的郵箱不存在了,被注銷了,所以這個問題無解了,按照正常流程是需要舊的郵箱驗證通過才能添加或者自己操作移除權限
#Stack Overflow: Run pod trunk info {podname} to find the owners. Contact one of the owners to give you access.  pod trunk add-owner需要其他成員進行驗證才行

參考

17. pod更新很慢咋辦呢?

  1. 使用國內清華的鏡像 https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/
  2. 條件允許的話 FQ

18. nil值不能用作布爾值來當判斷條件的坑

nil 不能用作判斷布爾值,

model.nickName = nil;
model.userName = @"小老虎";

//❌錯誤示范 如果為nil就判斷不了,@""可以判斷 
NSString *nickName = model.nickName? model.nickName : model.userName; 
//✅姿勢
NSString *nickName = (model.nickName && model.nickName.length)? model.nickName : model.userName;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM