iOS學習筆記:更新Xcode9後用iPhone X 運行遇到的一些問題

來源:互聯網
上載者:User

標籤:iphone x   運行   status   details   學習筆記   data   nta   修改   嵌套   

1. 控制台列印線程問題

Main Thread Checker: UI API called on a background thread: -[UIApplication statusBarOrientation]

PID: 4940, TID: 93956, Thread name: (none), Queue name: WriteLogQueue, QoS: 0

造成原因是因為原本 需要在主線程執行的代碼 被放在了子線程裡邊

解決方案:在scheme 裡邊取消主線程檢測 (不建議使用) 建議修改代碼 把出問題的代碼放在主線程裡面就行了

 

 

2.運行程式直接崩潰問題,起初崩潰直接跳到main.m檔案中 控制台列印的日誌也是一堆毫無頭緒的東西,沒有報錯資訊,也沒告訴崩在哪裡,

搜尋半天沒有有效解決方案,所以就開始了最基本的斷點調試,一點點調試之後報錯提示變成了下面:給了詳細的報錯資訊 

[Bugly]  Trapped uncaught exception ‘NSUnknownKeyException‘, reason: ‘[<UIStatusBar_Modern 0x7fab69509e40> valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.‘ 

(

0   CoreFoundation                      0x000000010b81612b __exceptionPreprocess + 171

1   libobjc.A.dylib                     0x000000010a92bf41 objc_exception_throw + 48

2   CoreFoundation                      0x000000010b816079 -[NSException raise] + 9

3   Foundation                          0x000000010a4179ae -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226

4   Foundation                          0x000000010a342d80 -[NSObject(NSKeyValueCoding) valueForKey:] + 284

5   chenghuiguang                       0x0000000104d50335 -[BaseNetWorkService addHeader] + 1125

6   chenghuiguang                       0x0000000104d4f9b6 -[BaseNetWorkService initOperationManager] + 854

7   chenghuiguang                       0x0000000104d4f622 -[BaseNetWorkService init] + 114

8   chenghuiguang                       0x0000000104eb481e -[WaittingViewController initData] + 62

9   chenghuiguang                       0x0000000104eb4799 -[WaittingViewController viewDidLoad] + 73

.

.


根據報錯提示找到了我的BaseNetWorkService檔案下 addHeader方法,再根據錯誤提示搜尋 查到了崩潰的原因 ,

詳細解答請參考連結:http://blog.csdn.net/lucky_xiaofeng310/article/details/78359336

 

由於iPhone X的狀態列是和其他版本手機差異比較大的,因此api 變化也比較大, iPhone X的狀態列是多嵌套了一層,多取一次即可

我的項目中用到了 使用狀態列中表徵圖判斷當前網路的具體狀態 ,所以用 iPhone X運行崩潰了

 

不能直接用 

[[[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];

需要做判斷UIStatusBar_Modern

    NSArray *subviewArray;

    // 不能用 [[self deviceVersion] isEqualToString:@"iPhone X"] 來判斷,因為模擬器不會返回 iPhone X

    if([[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {

        subviewArray = [[[[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"]       subviews];

    } else {

        subviewArray = [[[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];

    }

 如:

 

iOS學習筆記:更新Xcode9後用iPhone X 運行遇到的一些問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.