使用Xcode開發(fā),錯誤總結<持續(xù)更新ing>

前言

在這里,我會記錄下工作當中使用XCode遇到過的問題,及提供問題的解決方案。歡迎各位看官,拍磚。

1.問題描述:

fatal error: 'XCTest/XCTest.h' file not found

解決方法:

在項目報錯的target中,選擇 Building settings項中的Framework Search Paths添加$(PLATFORM_DIR)/Developer/Library/Frameworks

解決辦法圖示.png

2.問題描述:

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++庫,問題解決!

解決辦法圖示.png

3.問題描述:

在Xcode7發(fā)現(xiàn)的問題和解決方案如下

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)

解決辦法:

解決辦法.png

4.使用自動布局遇到的問題

錯誤日志打?。?/p>

 *** 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 出現(xiàn)這個錯誤的原因是,你所設置約束的這個控件和所依賴的控件沒有共同的父視圖。因為沒有共同的視圖作為參照,frame 就不能轉換到一個相同的坐標系。這個問題經常會出現(xiàn)在,我們創(chuàng)建了要設置約束的視圖,而沒有將它添加到父控件中,又或者,要設置約束的這個視圖和所依賴的視圖沒有共同的父視圖,也就是你遇到的這種情況。

解決辦法:創(chuàng)建控件時,先添加到父控件上,然后再設置約束。

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狀態(tài),真機調試,遇到的問題

Xcode提示:The executable was signed with invalid entitlements.
原因是,設置了code singing entitlements這一項內容(這是APP Group的內容,需要為它注冊一個group.com.xxx ID才能夠消除這個錯誤。)

錯誤描述.png

如果沒有使用到app group功能,就關閉它。


屏幕快照 2016-04-17 23.46.38.png

6.APP 的Build Active Architecture 設置為YES打包上傳appStore,遇到的問題

錯誤設置.png

Xcode提示:
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

正確設置.png

7.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(項目名字)出現(xiàn)這個錯誤信息

當新增加一個Target,并且pod install后,由于創(chuàng)建項目是默認創(chuàng)建的Target的Build Phases中引用了舊的.a,例如libPods.a,當新增加Targget后,libPods.a已經變成了libPods-Test.a,而新增加的Target名字為Second,依賴的.a為libPods-Second.a。所以libPods.a此時已經不再被引用,并且不會被生成,如果任何地方引用了就會報錯,解決辦法是出現(xiàn)問題的Target的Build Phases中刪除無用的.a引用,例如libPods.a (可以在下圖找到)

屏幕快照 2016-08-17 17.31.57.png

9.CocoaPods升級后(最新版本1.0.1),安裝第三方庫的時候會報如下錯誤:

The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete target.

原因:CocoaPods升級后,Podfile文件的內容格式要求發(fā)生了變化,必須指出指出所用第三方庫的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功能,登陸開發(fā)者賬號,檢查appID中的iCloud是否顯示 configuration,如果是顯示configuration,你如果使用到iCloud功能就可以繼續(xù)配置下去,如果沒有使用iCloud功能就不要勾選這個功能

截圖.png

完成后,重新生成一個描述文件,如圖所示


截圖2.png

下載新的描述文件,就可以真機調試了。

10.Xcode8無限閃退的解決方案##

系統(tǒng)升級到10.11.6以上、Xcode升級到Xcode8以上,出現(xiàn)經常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時,如果創(chuàng)建的是reuse cell,使用了類似如下的方法:

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier: CustomCellID];  

需要在viewDidLoad中注冊一個reUseCell:就能解決這樣的錯誤

[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier: CustomCellID];  
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容