ios5asihttprequestexc-bad-accessasiformdatarequest

setCompletionBlock: causes EXC_BAD_ACCESS only in simulator..it works fine on device


In the simulator, using ASIHTTPRequest's setCompletionBlock: message always causes an EXC_BAD_ACCESS error. Even setting NSZombieEnabled to YES does nothing to illuminate the situation.

__weak ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setCompletionBlock:^{
        int statusCode = [request responseStatusCode];
        NSLog(@"%d",statusCode);
          }];

 [request setFailedBlock:^{  
        // send statuscode error back
        int statusCode = [request responseStatusCode];
        NSLog(@"%d",statusCode);
    }];

    [request startAsynchronous];

Solution

  • Ok, so after spending 2 days, I finally found the solution: Fixing my linker flags

    Essentially you have to change -weak_library /usr/lib/libSystem.B.dylib to -weak-lSystem.

    I had originally added this because Urban Airship required it.

    Many thanks to following References:

    EXC_BAD_ACCESS when copying or retaining Block

    iPhone simulators crash on app launch