无法找到错误,EXC_BAD_ACCESS

时间:2013-03-21 14:03:28

标签: iphone objective-c exc-bad-access

上次我在Stackowerflow上发帖时,我搞砸了,因为我以为我知道的比以前更多。重命名方法使其变得更容易,并使一切变得非常混乱。所以我现在要再试一次。

无论如何,我的应用程序被Apple拒绝了几次,我找不到这个bug。我一直在运行模拟器以及AD-HOC安装,似乎无法找到错误甚至复制它。

我没有警告,并且一直在使用静态分析仪,但也找不到任何问题。

我是Objective C的新手并且认为我在使用类方法时遇到了什么问题,但我不确定。

这是最后一个,崩溃的类方法“itemStatus”。

我正在使用ARC。

非常感谢任何帮助。

   Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x432b2b10
    Crashed Thread:  0

    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0   libobjc.A.dylib                 0x3a3c3526 objc_retain + 6
    1   Kebunno                     0x0008928a +[DynamoDBManager itemStatus] + 418
    2   Kebunno                     0x000894de +[DynamoDBManager getItem:] + 170
    3   Kebunno                     0x000908f6 __44-[KebunnoViewController itemPressed]_block_invoke + 362

头等舱

@interface KebunnoViewController ()

// Interface declarations here

@end


@implementation KebunnoViewController

- (IBAction)itemPressed:(id)sender {
    NSString *itemID = _itemID.text;
    NSString *reference = _reference.text;


    BOOL itemCorrect = NO;
    if([ItemHelpClass validItem:itemID]){
    itemCorrect = YES;
    }

    if(!itemCorrect){
        [[ItemHelpClass showItemNotCorrect:self] show];
        return;
    }


    else if(itemCorrect){
        [self startCancelTimer];
        [self disableButtons];

        dispatch_queue_t backgroundQueue = dispatch_queue_create("background queue", NULL);
        dispatch_async(backgroundQueue, ^{
            NSString *itemStatus;
            itemStatus = [DynamoDBManager getItem:itemID]; //crash

         if([itemStatus isEqualToString:NETWORK_ERROR] || 
          [itemStatus  isEqualToString:AMAZON_ERROR]){
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self enableButtons];
                    [[ItemHelpClass showSomethingWentWrong:self] show];
                });
            }

//Code continues
}

@end

另一个名为DynamoDBMangar.m的文件

@implementation DynamoDBManager

+(NSString*)getItem:(NSString *)itemID {
    NetworkStatus netStatus = 
    [[Reachability reachabilityForInternetConnection]currentReachabilityStatus];

    if(netStatus == NotReachable)
    {
        return NETWORK_ERROR;
    }

    NSString *itemStatus = [self itemStatus]; //crash
    if([itemStatus isEqualToString: ITEM_BORROWED]){
        return ITEM_BORROWED;
    }
    else if([itemStatus isEqualToString:NETWORK_ERROR])
    {
        return NETWORK_ERROR;
    }

//Code continues
}



+(NSString*) itemStatus{
    NetworkStatus netStatus = [[Reachability reachabilityForInternetConnection]currentReachabilityStatus];
    if(netStatus == NotReachable)
    {
        return NETWORK_ERROR;
    }


    @try
    {

        DynamoDBGetItemRequest *request = [[DynamoDBGetItemRequest alloc] initWithTableName: TABLE_CONTENT andKey:[[DynamoDBKey alloc] initWithHashKeyElement:
                                                                   [[DynamoDBAttributeValue alloc] initWithS:[ItemHelpClass getItem]]]];

        DynamoDBGetItemResponse *response = [[AmazonClientManager ddb] getItem:request];
        if(response){
            if(((DynamoDBAttributeValue *)[response.item objectForKey:@"UID_ID"]).s){
                return ITEM_BORROWED;
            }
            else{
                return ITEM_NOT_BORROWED;
            }
        }

    }@catch (NSException *exception)
    {
        [AmazonClientManager wipeCredentialsOnAuthError:exception];
    }
    return NETWORK_ERROR;

}

@end

编辑:CPU状态

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x200c55c0    r1: 0x432b2b00      r2: 0x00000002      r3: 0x00000020
    r4: 0x00000001    r5: 0x200a2d10      r6: 0x1f5c67f0      r7: 0x2fd95a08
    r8: 0x200a4260    r9: 0x000fc09c     r10: 0x1f5c4c40     r11: 0x200a44e0
    ip: 0x3c33c050    sp: 0x2fd95960      lr: 0x0008928f      pc: 0x3a3c3526
  cpsr: 0x00000030

1 个答案:

答案 0 :(得分:-1)

@catch (NSException *exception)
    {
        [AmazonClientManager wipeCredentialsOnAuthError:exception];
        return NULL;
    }