2013-03-21 85 views
0

我上次發佈在Stackowerflow上,我搞砸了,因爲我認爲我知道的比我多。重命名方法使其更容易,並且使所有事情變得非常混亂。所以我現在要再試一次。不能發現錯誤,EXC_BAD_ACCESS

無論如何,我的應用程序已被Apple拒絕了幾次,我找不到這個bug。我一直在運行模擬器以及AD-HOC安裝,似乎無法找到該錯誤,甚至無法複製它。

我沒有警告,一直在使用靜態分析器,也找不到任何問題。

我是新來的目標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

不要公關帶'get'的efix方法;這是保留給一個非常具體的模式(通過引用傳遞),這不是它。 – bbum 2013-03-21 14:14:19

+0

好的,你在那裏。我習慣於java編程並使用「getters」和「setters」。應該避免在目標中使用它C – M3rd0n 2013-03-21 14:18:19

+1

不用擔心 - 不是問題的根源,但與基礎API的一致性總是好的。你如何聲明和初始化各種常量(即NETWORK_ERROR,ITEM_BORROWED等)? – bbum 2013-03-21 14:19:12

回答

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

這應該如何幫助? – JeremyP 2013-03-21 15:49:36

+0

我假設NETWORK_ERROR不完全是一個NSString對象,至少在編譯時沒有。這是itemStatus = [[DynamoDBManager getItem:itemID] retain]隱式調用方法,負責崩潰。 – 2013-03-21 16:52:51