前言
在这里,我会记录下工作当中使用XCode遇到过的问题,及提供问题的解决方案。欢迎各位看官,拍砖。
1.问题描述:
fatal error: 'XCTest/XCTest.h' file not found
解决方法:
在项目报错的target中,选择 Building settings项中的Framework Search Paths添加$(PLATFORM_DIR)/Developer/Library/Frameworks
解决办法图示.png2.问题描述:
mac上使用g++编译出错“Undefined symbols for architecture x86_64:”
日志输出如下:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK
略。。。。
解决方法:
编译选项添加-lstdc++,即使用标准C++库,问题解决!
解决办法图示.png3.问题描述:
在Xcode7发现的问题和解决方案如下
Undefined symbols for architecture x86_64:
"_u_errorName", referenced from:
_rkl_NSExceptionForRegex in RegexKitLite.o
_rkl_makeNSError in RegexKitLite.o
_rkl_userInfoDictionary in RegexKitLite.o
_rkl_NSExceptionForRegex in MOBFoundation
_rkl_userInfoDictionary in MOBFoundation
"_u_strlen", referenced from:
_rkl_userInfoDictionary in RegexKitLite.o
_rkl_userInfoDictionary in MOBFoundation
"_uregex_appendReplacement", referenced from:
_rkl_replaceAll in RegexKitLite.o
_rkl_replaceAll in MOBFoundation
"_uregex_appendTail", referenced from:
_rkl_replaceAll in RegexKitLite.o
_rkl_replaceAll in MOBFoundation
"_uregex_clone", referenced from:
-[RKLBlockEnumerationHelper initWithRegex:options:string:range:error:] in RegexKitLite.o
-[MOBFRKLBlockEnumerationHelper initWithRegex:options:string:range:error:] in MOBFoundation
"_uregex_close", referenced from:
_rkl_clearCachedRegex in RegexKitLite.o
_rkl_clearCachedRegex in MOBFoundation
"_uregex_end", referenced from:
_rkl_performRegexOp in RegexKitLite.o
_rkl_search in RegexKitLite.o
_rkl_findRanges in RegexKitLite.o
_rkl_performRegexOp in MOBFoundation
_rkl_search in MOBFoundation
_rkl_findRanges in MOBFoundation
"_uregex_find", referenced from:
_rkl_search in RegexKitLite.o
_rkl_search in MOBFoundation
"_uregex_findNext", referenced from:
_rkl_search in RegexKitLite.o
_rkl_replaceAll in RegexKitLite.o
_rkl_search in MOBFoundation
_rkl_replaceAll in MOBFoundation
"_uregex_groupCount", referenced from:
_rkl_getCachedRegex in RegexKitLite.o
_rkl_getCachedRegex in MOBFoundation
"_uregex_open", referenced from:
_rkl_getCachedRegex in RegexKitLite.o
_rkl_getCachedRegex in MOBFoundation
"_uregex_reset", referenced from:
_rkl_replaceAll in RegexKitLite.o
_rkl_replaceAll in MOBFoundation
"_uregex_setText", referenced from:
-[RKLBlockEnumerationHelper initWithRegex:options:string:range:error:] in RegexKitLite.o
_rkl_clearCachedRegexSetTo in RegexKitLite.o
_rkl_setCachedRegexToString in RegexKitLite.o
-[MOBFRKLBlockEnumerationHelper initWithRegex:options:string:range:error:] in MOBFoundation
_rkl_performRegexOp in MOBFoundation
_rkl_clearCachedRegexSetTo in MOBFoundation
"_uregex_start", referenced from:
_rkl_performRegexOp in RegexKitLite.o
_rkl_search in RegexKitLite.o
_rkl_findRanges in RegexKitLite.o
_rkl_performRegexOp in MOBFoundation
_rkl_search in MOBFoundation
_rkl_findRanges in MOBFoundation
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法:
解决办法.png4.使用自动布局遇到的问题
错误日志打印:
*** Assertion failure in -[MASViewConstraint install], /Users/lcy/SVN/cheeryMusic_New/Factory/Branch/Countercurrent/Countercurrent/Pods/Masonry/Masonry/MASViewConstraint.m:345
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'couldn't find a common superview of ......
原因:'couldn't find a common superview for 出现这个错误的原因是,你所设置约束的这个控件和所依赖的控件没有共同的父视图。因为没有共同的视图作为参照,frame 就不能转换到一个相同的坐标系。这个问题经常会出现在,我们创建了要设置约束的视图,而没有将它添加到父控件中,又或者,要设置约束的这个视图和所依赖的视图没有共同的父视图,也就是你遇到的这种情况。
解决办法:创建控件时,先添加到父控件上,然后再设置约束。
UIView *autoLayoutContentView = [[UIView alloc] init];
[_contentView addSubview:autoLayoutContentView];
[autoLayoutContentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view);
make.right.equalTo(self.view);
make.top.equalTo(self.view);
make.bottom.equalTo(self.view);
}];
5.APP设置为release状态,真机调试,遇到的问题
Xcode提示:The executable was signed with invalid entitlements.
原因是,设置了code singing entitlements这一项内容(这是APP Group的内容,需要为它注册一个group.com.xxx ID才能够消除这个错误。)
如果没有使用到app group功能,就关闭它。
屏幕快照 2016-04-17 23.46.38.png
6.APP 的Build Active Architecture 设置为YES打包上传appStore,遇到的问题
错误设置.pngXcode提示:
ERROR ITMS-90502: "Invalid Bundle. Apps that only contain the arm64 slice must also have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist."
ERROR ITMS-90530: "Invalid MinimumOSVersion. Apps that only support 64-bit devices must specify a deployment target of 8.0 or later. MinimumOSVersion in 'Countercurrent.app' is '7.0'."
解决办法如下:
这个属性设置为yes,是为了debug的时候编译速度更快,它只编译当前的architecture版本。
而设置为no时,会编译所有的版本。
补充:如果项目中使用pod来引入第三方库,需要在Pods项目文件中,对每一个第三方库的Build Active Architecture 设置为NO
正确设置.png7.Unexpected Machine Code
Build Settings 中 Enable Bitcode 对应为YES,Build Active Architecture 设置为NO,打包上传AppStore后收到邮件。
Unexpected Machine Code - Your upload contains both bitcode and native machine code. When you provide bitcode, it's not necessary to include machine code as well. To reduce the size of your upload, use Xcode 7.3 or later, or any other toolchain that removes machine code.
解决办法:有网友说不影响的,点击查看
8.library not found for -lPods-XXXX(项目名字)出现这个错误信息
当新增加一个Target,并且pod install后,由于创建项目是默认创建的Target的Build Phases中引用了旧的.a,例如libPods.a,当新增加Targget后,libPods.a已经变成了libPods-Test.a,而新增加的Target名字为Second,依赖的.a为libPods-Second.a。所以libPods.a此时已经不再被引用,并且不会被生成,如果任何地方引用了就会报错,解决办法是出现问题的Target的Build Phases中删除无用的.a引用,例如libPods.a (可以在下图找到)
屏幕快照 2016-08-17 17.31.57.png9.CocoaPods升级后(最新版本1.0.1),安装第三方库的时候会报如下错误:
The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete target.
原因:CocoaPods升级后,Podfile文件的内容格式要求发生了变化,必须指出指出所用第三方库的target。
解决步骤:
(1)检查CocoaPods的版本
pod --version
(2) 升级或安装最新版本(目前版本1.0.1)
注意:如果cocoapods已经是1.0.1版本,则跳过该步骤直接进入第三个步骤。
升级命令:sudo gem update -n /usr/local/bin --system
安装命令:sudo gem install -n /usr/local/bin cocoapods
(3)修改Podfile的内容
修改前的Podfile文件的内容:
platform:ios,'7.0'
pod 'MJRefresh', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.6'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'AFNetworking', '~> 3.1.0'
修改后的Podfile文件的内容:
platform:ios,'7.0'
target "MyProject" do
pod 'MJRefresh', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.5'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'AFNetworking', '~> 3.1.0'
end
1.更新库命令:
pod update --verbose --no-repo-update
2.安装库命令
pod install --verbose --no-repo-update
3.在Podfile文件中需要明确指出使用第三方库的target,这里target后面跟的就是自己项目本身的Target;也就是项目中的tagrets中的那个项目名称。
4.注意:Podfile文件必须跟xxxx.xcodeproj工程文件在同一个目录下
10.更新过Provisioning Profile之后,真机调试报如下错误:
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.
解决办法:
有些人是因为APPId中勾选了 icloud功能,登陆开发者账号,检查appID中的iCloud是否显示 configuration,如果是显示configuration,你如果使用到iCloud功能就可以继续配置下去,如果没有使用iCloud功能就不要勾选这个功能
完成后,重新生成一个描述文件,如图所示
截图2.png
下载新的描述文件,就可以真机调试了。
10.Xcode8无限闪退的解决方案##
系统升级到10.11.6以上、Xcode升级到Xcode8以上,出现经常xcode闪退的情况,而且频率还蛮高的
原因:图片预览插件KSImageNamed-Xcode和xcode8不兼容导致的,只要把图片预览插件删除即可
解决步骤:
1-按住 command + shift +G 进入到路径入口
2-拷贝路径: 图片预览插件路径
~/Library/Developer/Xcode/Plug-ins
3-将里面的bundle删除
4-重启xcode8即可
11.真机调试报错:This application's application-identifier entitleme##
错误日志:This application's application-identifier entitlement does not match that of the installed application. These values must match for an upgrade to be allowed
解决步骤:
1、Xcode-Window->Devices
2、选中你的设备,在左下角的installed Apps中删除之前安装的这个App
3、重新编绎即可
12. 错误信息:failed to obtain a cell from its dataSource##
使用iOS的tableView时,如果创建的是reuse cell,使用了类似如下的方法:
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier: CustomCellID];
需要在viewDidLoad中注册一个reUseCell:就能解决这样的错误
[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier: CustomCellID];
网友评论