iOS項(xiàng)目開(kāi)發(fā)中Crash匯總

錯(cuò)誤1、


圖1

原因: 從上面的報(bào)錯(cuò)信息可以看出,主線程在運(yùn)行的時(shí)候子線程修改了主線程UI的布局約束,在iOS開(kāi)發(fā)中,所有的有關(guān)界面UI的更新操作必須奧在主線程中完成。這樣的錯(cuò)誤很容易出現(xiàn)在使用block的時(shí)候,因?yàn)閎lock就是在子線程中進(jìn)行的,所以回顧了剛才自己寫(xiě)的代碼,發(fā)現(xiàn)還真是粗心了。解決的辦法就是在剛才寫(xiě)的代碼中有關(guān)針對(duì)UI更新的操作放到主線程中。

錯(cuò)誤2、

Warning: Attempt to present <UIAlertController: 0x7fd2f8609240> on <ViewController: 0x7fd2f85090b0> whose view is not in the window hierarchy!

// 原因: 今天在寫(xiě)UIAlertController的時(shí)候,在ViewDidLoad中聲明并模態(tài)推出的時(shí)候出現(xiàn)了一個(gè)錯(cuò)誤,這個(gè)錯(cuò)誤網(wǎng)上查了一下,原因是在presnet的時(shí)候viewDidLoad還沒(méi)有執(zhí)行完成,只有viewDidLoad執(zhí)行完成之后,正常使用。
在控制器加載的時(shí)候,不能使用這個(gè)去調(diào)用,這樣就必須向辦法延時(shí)才行。
由于是Demo,習(xí)慣性的直接寫(xiě)在viewDidLoad中,我最后使用一個(gè)Button來(lái)出發(fā)這個(gè)動(dòng)作,就沒(méi)有以上錯(cuò)誤了。

錯(cuò)誤3

Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:]
// 可能是XIB中多脫出一個(gè)控件導(dǎo)致

錯(cuò)誤4

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x1700063f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
可能是xib的某個(gè)控件沒(méi)有對(duì)應(yīng)的關(guān)聯(lián)上

錯(cuò)誤5

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Cache
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    這個(gè)函數(shù)的返回值是個(gè)null?。?br> 查stackoverflow 找到下面的解。
CellIdentifier I bet your cellForRowAtIndexPath is returning null.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"Photos";

    /** NOTE: This method can return nil so you need to account for that in code */
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // NOTE: Add some code like this to create a new cell if there are none to reuse
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    NSString *string = [[self.photosInPlace objectAtIndex:indexPath.row]     valueForKeyPath:@"description._content"];

    cell.textLabel.text = string;

    return cell;
}
That's probably why [UITableView _configureCellForDisplay:forIndexPath:] is failing... becausecellForRowAtIndexPath is returning a null value and then configureCellForDisplay is expecting aUITableViewCell.

通過(guò)解決這個(gè)錯(cuò)誤,認(rèn)識(shí)到一點(diǎn):
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中一定要注意避免所返回的cell為nil的情況出現(xiàn)。實(shí)際上,從iOS5開(kāi)始,一個(gè)表視圖可以跟蹤與特定的可重用標(biāo)識(shí)符相關(guān)聯(lián)的nib文件。UITableView的
dequeueReusableCellWithIdentifier:方法現(xiàn)在很智能,就算沒(méi)有可用的單元,它也可以使用這個(gè)注冊(cè)了的nib文件來(lái)加載一個(gè)新單元。這就意味著,只要我們?yōu)楸硪晥D注冊(cè)了所有將要使用到的可重用標(biāo)識(shí)符,dequeueReusableCellWithIdentifier:方法就會(huì)始終返回一個(gè)單元,它決不會(huì)返回nil。因此,我們可以刪除那些用于檢查cell為nil的代碼行,因?yàn)檫@種情況永遠(yuǎn)不會(huì)發(fā)生。
所以,這里更好的做法是用如下方法來(lái)實(shí)現(xiàn)-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    static NSString *CellTableIdentifer = @"CellTableIdentifer";  
    //tableView注冊(cè)nib文件  
    static BOOL nibsRegistered = NO;  
    if(!nibsRegistered)  
    {  
        UINib *nib = [UINib nibWithNibName:@"TableViewItemCell" bundle:nil];  
        [tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifer];  
        nibsRegistered = YES;  
    }  
      
    TableViewItemCell * cell = [tabView dequeueReusableCellWithIdentifier:CellTableIdentifer];  
    cell.textLabel.text = @"xxxxx";  
    return cell;  
}  

錯(cuò)誤6

Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11be33cc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11ac826f0). One of the two will be used. Which one is undefined.

屏蔽雜亂無(wú)章的log,在xcode Edit scheme -> Run -> Arguments-> Environment Variables->Name:OS_ACTIVITY_MODE Value:disable

錯(cuò)誤7

This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

權(quán)限以及相關(guān)設(shè)置出問(wèn)題:

<!-- 相冊(cè) --> 
<key>NSPhotoLibraryUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)相冊(cè)</string> 
<!-- 相機(jī) --> 
<key>NSCameraUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)相機(jī)</string> 
<!-- 麥克風(fēng) --> 
<key>NSMicrophoneUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)麥克風(fēng)</string> 
<!-- 位置 --> 
<key>NSLocationUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)位置</string> 
<!-- 在使用期間訪問(wèn)位置 --> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>App需要您的同意,才能在使用期間訪問(wèn)位置</string> 
<!-- 始終訪問(wèn)位置 --> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>App需要您的同意,才能始終訪問(wèn)位置</string> 
<!-- 日歷 --> 
<key>NSCalendarsUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)日歷</string> 
<!-- 提醒事項(xiàng) --> 
<key>NSRemindersUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)提醒事項(xiàng)</string> 
<!-- 運(yùn)動(dòng)與健身 --> 
<key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)運(yùn)動(dòng)與健身</string> 
<!-- 健康更新 --> 
<key>NSHealthUpdateUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)健康更新 </string> 
<!-- 健康分享 --> 
<key>NSHealthShareUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)健康分享</string> 
<!-- 藍(lán)牙 --> 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)藍(lán)牙</string> 
<!-- 媒體資料庫(kù) --> 
<key>NSAppleMusicUsageDescription</key> 
<string>App需要您的同意,才能訪問(wèn)媒體資料庫(kù)</string>

如果不起作用,可以請(qǐng)求后臺(tái)權(quán)限,類似于這樣:

<key>UIBackgroundModes</key>
<array> 
<!-- 在這里寫(xiě)上你在后臺(tái)模式下要使用權(quán)限對(duì)應(yīng)的key --> 
<string>location</string>
...
</array>

/**  Plist 字段*/
麥克風(fēng)權(quán)限:Privacy - Microphone Usage Description
通訊錄權(quán)限: Privacy - Contacts Usage Description
藍(lán)牙權(quán)限:Privacy - Bluetooth Peripheral Usage Description
語(yǔ)音轉(zhuǎn)文字權(quán)限:Privacy - Speech Recognition Usage Description
日歷權(quán)限:Privacy - Calendars Usage Description
定位權(quán)限:Privacy - Location When In Use Usage Description
定位權(quán)限: Privacy - Location Always Usage Description

待續(xù)……

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容