匯總一些在平時開發中遇到的BUG,不定期更新
用AutoLayout有時候會出現:
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x17ef4e10 V:[UIView:0x17ee9e00]-(0)-| (Names: '|':UIView:0x17ef3e10 )>",
"<NSLayoutConstraint:0x17ef4e70 V:|-(0)-[UIView:0x17ee9e00] (Names: '|':UIView:0x17ef3e10 )>",
"<NSLayoutConstraint:0x17dc8650 'UIView-Encapsulated-Layout-Height' V:[UIView:0x17ef3e10(455)]>",
"<NSAutoresizingMaskLayoutConstraint:0x17dc86b0 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x17ef3e10] (Names: '|':UIViewControllerWrapperView:0x17d7ac80 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17d90d50 h=--& v=--& UIView:0x17ee9e00.midY == + 184>"
)
錯誤原因可能是:在添加約束的時候,比如說 水平方向的約束leading trailing和 weight 沖突了系統會幫我們去掉寬度的限制
解決方法: 重新添加約束,選擇性的不添加寬度<根據情況不添加一些約束>
JSON解析數據 for循環嵌套錯誤:
-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7fff32fabdc0
JSON解析數據,方式不對:
-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7f85d4110700
原因: 解析字典時,定義的是數組;解析數組時,定義的是字典
setValue:ForUnderfinedKey:]:this class is not key value coding
原因:連線出問題了
-[ViewController up]: unrecognized selector sent to instance 0x8c50af0
原因:某個對象沒有實現某個方法
"_SCNetworkReachabilityCreateWithName", referenced from:
原因:靜態庫中依賴的一些框架沒有導入.如果靜態庫中用到了框架就必須導入
"std::terminate()", referenced from:
但凡看到錯誤提示中提示兩個冒號,表示C++代碼, 默認情況下Xcode創建的工程是不支持C++.
如何解決: 將工程中任意一個文件的后綴改為.MM即可
.c --> C代碼
.cpp --> C++代碼
.m --> C代碼 + OC代碼
.MM -->C代碼 + OC代碼 + C++代碼
Undefined symbols for architecture x86_64:
這個錯誤, 一般是指用到的三方框架不支持64位手機
解決方式: 打開工程 --> Build Settings --> All --> Architectures --> Debug\Release --> Other -->修改為 $(ARCHS_STANDARD_32_BIT)
真機測試
/Users//SDKs/PolymerPay/Library/mobStat/libSDK.a(**ForSDK.o)’does not contain bitcode. You must rebuild it with bitcode enabled (Xcodesetting ENABLE_BITCODE), obtain an updated library from the vendor, or disablebitcode for this target. for architecture arm64
/...linker command failed with exit code 1 (use -v to see invocation)
看警告可以得到的信息是"引入的一個第三方庫不包含bitcode"。至于什么是bitcode,我是不太明白是神馬意思,通過查閱相關資料,得出的結論是:這個東西應該和包的優化有關。
在上面的錯誤提示中,提到了如何處理我們遇到的問題:
You must rebuild it with bitcode enabled(Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, ordisable bitcode for this target. for architecture arm64
意思就是說:要不你第三方類庫支持 bitcode 要不你就關掉它
好吧,我們只能選擇后者了
我們來看看他在那里?
某些另類的Bitcode報錯
在進行了上述操作之后,某些第三方庫或者靜態庫出現了一下報錯信息:
std::__1::basic_istream<char, std::__1::char_traits<char> >::~base_istream()
如圖:
錯誤原因:該庫是c++和oc混編
解決方案:在項目配置中-->Linked Frameworks and Libraries 添加庫 libstdc++.tbd
編譯時報錯
_OBJC_CLASS_$_xxx第三方庫", referenced from: objc-class-ref in xxxViewController.o
報錯原因:
該第三方庫不支持模擬器調試,只能真機測試
白名單
在進行APP之間的跳轉問題上,有時候代碼完全沒有問題,卻死活不進行跳轉。
原因是從xcode7開始(iOS9開始),程序里面所有的其他網絡連接都得添加在白名單里面,不然是無法響應的!
解決方案:
在plist文件中里面添加一個key為“LSApplicationQueriesSchemes”數組值,里面添加包括string型的“scheme”,其他的可根據需求依次添加。
如:需要qq登錄、分享
添加:mqqapi、mqq、mqqopensdkapiV2、mqqOpensdkSSoLogin、mqzone、mqzoneopensdkapiV2、mqzoneopensdkapi
HTTP & HTTPS
在iOS9,蘋果將HTTP換成了HTTPS!真是反程序猿的設計
為此,要么后臺大改,全部換成HTTPS,要么就繼續延用現有。
延用現有如圖設置:在plist文件中里面添加一個key
AFNetworking
無法解析數據,error錯誤信息如下:
原因:
AFNetworking中的ContentTypes設置只有最最最通用的幾個而已(貌似是三個),然而不同的后臺程序員的編碼格式可能不同,當AFN中沒有該同事的格式時,不論如何修改都將無濟于事。
解決方案:
像上面14_3圖所示,缺少的content-type 是 text/plain,添加上去即可?。ㄐ⌒〗ㄗh:修改第三方庫源碼時,盡量注釋掉原來的Demo,在下面重寫)
模擬器使用CoreLocation定位
不進入定位的代理方法,并且出現錯誤信息:
Error Domain=kCLErrorDomain Code=0 “(null)”
解決方案:
1、確保所有關于定位的配置信息都已齊全,<a href="http://www.lxweimin.com/p/0c0905e261a7">配置信息參考這篇文章</a>。
2、進行下列操作:project-->scheme-->edit scheme-->options-->core location-->allow location simulation配置選中,將Default Location設置一個默認的位置。
3、將simulator-->reset content and settings 重啟。
4、運行程序,完成調試。
截圖如下:
PUSH通知推送:
The 'Apple Push Notification' feature is only available to users enrolled in xxx
原因:開發者賬號不是付費賬號,沒有推送服務的權限
解決:
1、換一個付費賬號。
2、注釋掉推送部分,先處理其他需求。
3、如果硬是要使用推送部分代碼可以進行以下操作:
1、在projectName.xcodeproj文件上右鍵“顯示包內容”
2、用文本編輯器打開“project.pbxproj”文件(.pbxproj!不要找錯了文件!)
3、查找:
com.apple.Push = { enabled = 1; };
修改為:
com.apple.Push = { enabled = 0; };
4、重新編譯即可
關于在Xcode 9.0+ 運行后的項目,在Xcode 7 or 8 中運行報錯的問題
報錯信息:
ld: framework not found FileProvider for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
原因:靜態庫用Xcode9打包,用Xcode8編譯的話就會報錯
解決方案:
1、確保你的Mac上有 Xcode 9.0+版本,點擊此處下載Xcode。
2、打開Finder-->應用程序-->找到Xcode 9.0+ --> 右鍵‘顯示報內容’
3、進入路徑/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/
4、找到報錯的 not found 文件(Copy the 'FileProvider.framework'
)
5、應用程序中找到Xcode 7 or 8,再次執行步驟 2、3、進入路徑,將報錯framework粘貼到 Xcode 7 or 8 路徑里面。
6、Xcode 7 or 8 中打開項目,command+shift+K 清除緩存,重新編譯即可。(一點要clean,否則會一直報錯)
點擊查看 Stack Overflow 上的案例