首页 > 技术文章 > 记录iOS踩的一些坑

wgb1234 2020-04-12 09:27 原文

总结以前碰到过的相关问题,记录一波~


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
# 执行完

推荐阅读