特设iPhone SIGSEGV在设备和设备上进行调试时崩溃模拟器工作

时间:2012-08-21 17:44:31

标签: iphone ios-simulator automatic-ref-counting asihttprequest sigsegv

我尝试登录后,应用程序立即崩溃,因此它不能成为看门狗内存问题

原因:_mh_execute_header 尝试使用ASIHTTPRequest发出网络请求时,应用程序崩溃。 请求永远不会触及服务器。 ASIHTTPRequest:我使用-fno-objc-arc从ARC中省略ASIHTTPRequest。

我认为以下呼叫导致我的问题,因为我的呼叫在我发出请求时甚至从未接触过服务器。任何帮助将不胜感激!

呼叫:

NSDictionary *response = [[NetworkManager sharedManager] loginWithName:name password:pwd];

方法:

- (NSDictionary *)loginWithName:(NSString *)name password:(NSString *)pwd
{
    NSURL *url = [NSURL URLWithString:@"http://www.test.com/keys"];
    NSArray *values = [NSArray arrayWithObjects:@"iphone", @"iphone@test.com", name, pwd, nil];
    NSArray *keys = [NSArray arrayWithObjects:@"name", @"email", @"username", @"password", nil];
    NSDictionary *response = [self startNetworkPOSTRequestWithUrl:url 
                                                       postValues:values 
                                                          forKeys:keys];
    return response;
}

堆栈追踪:

 Thread: Unknown Name (Crashed)
    0     libobjc.A.dylib                     0x37b9ef7e objc_msgSend + 21
    1     Test                          0x000dcda5 _mh_execute_header + 126373
    2     Test                          0x000dc4b9 _mh_execute_header + 124089
    3     Test                          0x000cd801 _mh_execute_header + 63489
    4     Test                          0x000ce39d _mh_execute_header + 66461
    5     Test                          0x000cf561 _mh_execute_header + 71009
    6     Test                          0x000d3e3d _mh_execute_header + 89661
    7     UIKit                               0x3334ccbd -[UITextField keyboardInput:shouldInsertText:isMarkedText:] + 148
    8     UIKit                               0x3334cc1f -[UIFieldEditor keyboardInput:shouldInsertText:isMarkedText:] + 94
    9     UIKit                               0x3334cbb9 -[UIKeyboardImpl callShouldInsertText:] + 108
    10   UIKit                               0x3334bb5b -[UIKeyboardImpl addInputString:fromVariantKey:] + 114
    11   UIKit                               0x3334bae1 -[UIKeyboardImpl handleStringInput:fromVariantKey:] + 164
    12   UIKit                               0x3334a775 -[UIKeyboardImpl handleKeyEvent:] + 1320
    13   UIKit                               0x334e48a3 -[UIKeyboardLayoutStar sendStringAction:forKey:isPopupVariant:] + 486
    14   UIKit                               0x33348dcd -[UIKeyboardLayoutStar touchUp:] + 3196
    15   UIKit                               0x333480fd -[UIKeyboardLayout touchesEnded:withEvent:] + 380
    16   UIKit                               0x3324b92b -[UIWindow _sendTouchesForEvent:] + 318
    17   UIKit                               0x3324b319 -[UIWindow sendEvent:] + 380
    18   UIKit                               0x33231695 -[UIApplication sendEvent:] + 356
    19   UIKit                               0x33230f3b _UIApplicationHandleEvent + 5826
    20   GraphicsServices                    0x373f022b PurpleEventCallback + 882
    21   CoreFoundation                      0x357d1523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
    22   CoreFoundation                      0x357d14c5 __CFRunLoopDoSource1 + 140
    23   CoreFoundation                      0x357d0313 __CFRunLoopRun + 1370
    24   CoreFoundation                      0x357534a5 CFRunLoopRunSpecific + 300
    25   CoreFoundation                      0x3575336d CFRunLoopRunInMode + 104
    26   GraphicsServices                    0x373ef439 GSEventRunModal + 136
    27   UIKit                               0x3325fcd5 UIApplicationMain + 1080
    28   Test                          0x000bfc1b _mh_execute_header + 7195

startNetworkPOSTRequestWithUrl方法的内容:

- (NSDictionary *)startNetworkPOSTRequestWithUrl:(NSURL *)url
                                      postValues:(NSArray *)values
                                         forKeys:(NSArray *)keys
{
    NSLog(@"saved user info: %@", values);
    __unsafe_unretained __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    __block NSDictionary *response;
    int num = [values count];
    __block BOOL success = YES;

    for (int i = 0; i < num; i++)
    {
        [request setPostValue:[values objectAtIndex:i] forKey:[keys objectAtIndex:i]];
    }

    [request setDelegate:self];
    [request setUseCookiePersistence:NO];
    [request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        response = [responseString JSONValue];
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"\nError: %@", error.localizedDescription);
        NSString *responseString = [request responseString];
        NSLog(@"\nError Response: %@", responseString);
        NSLog(@"\nurl: %@",url);
        success = NO;
    }];
    [request startSynchronous];

    if (success == NO)
    {
        return nil;
    }

    if (![(NSString *)[response valueForKey:@"status"] isEqualToString:@"success"])
    {
        NSLog(@"response: %@",response);
        return nil;
    }

    return (NSDictionary *)[response valueForKey:@"response"];
}

3 个答案:

答案 0 :(得分:2)

我找到了另一个解决我的一些问题的奇怪解决方法:

Target > Build Settings > Apple LLVM compiler 4.0 - Code Generation > Optimization Level下,我将Ad Hoc优化更改为None - 远离默认Fastest, Smallest [-Os],这样我就可以创建一个正常工作的ipa。

虽然这确实提供了一种解决方法,但考虑到我可能没有进行任何优化的其他后果,它确实不太理想。

但我认为这暗示我的一些潜在问题与记忆有关 - 任何人都可以对此提出任何见解吗?

答案 1 :(得分:1)

您正在执行同步请求,因此您不需要故障块或完成块。这将消除所有__block的东西,并使它的内存明显变得不那么奇怪。

- (IBAction)grabURL:(id)sender
{
  NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
  ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  [request startSynchronous];
  NSError *error = [request error];
  if (!error) {
    NSString *response = [request responseString];
  }
}

我是从http://allseeing-i.com/ASIHTTPRequest/How-to-use

的顶部得到的

答案 2 :(得分:1)

谢谢兰德尔。 startSynchronous可能有点用词不当。这是方法定义:

- (void)startSynchronous
{
#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING
    ASI_DEBUG_LOG(@"[STATUS] Starting synchronous request %@",self);
#endif
    [self setSynchronous:YES];
    [self setRunLoopMode:ASIHTTPRequestRunLoopMode];
    [self setInProgress:YES];

    if (![self isCancelled] && ![self complete]) {
        [self main];
        while (!complete) {
            [[NSRunLoop currentRunLoop] runMode:[self runLoopMode] beforeDate:[NSDate distantFuture]];
        }
    }

    [self setInProgress:NO];
}