Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

NSURLConnection+BlocksKit FailureBlock error #75

Closed
brspurri opened this issue Apr 12, 2012 · 9 comments
Closed

NSURLConnection+BlocksKit FailureBlock error #75

brspurri opened this issue Apr 12, 2012 · 9 comments

Comments

@brspurri
Copy link

Hi there,

I've been using NSURLConnection+BlocksKit successfully for a while now. However, I just upgraded to iOS 5.1 and Xcode 4.3.2 (as well as migrated to the debugger to lldb), and I now get exceptions on the following line:

myConnection.failureBlock = ^(NSURLConnection *connection, NSError *error) {

The entire snippet is:

NSURLRequest *loginRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:loginUrlString]];
NSURLConnection *myConnection = [NSURLConnection 
myConnection.successBlock = ^(NSURLConnection *connection, NSURLResponse *response, NSData *responseData){
   NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
   //Do some stuff
   [responseString release];
};

myConnection.failureBlock = ^(NSURLConnection *connection, NSError *error)  {
};

This fails when myConnection.failureBlock is included. If I comment it out, it runs perfect.

Any idea why this is? I just pulled the latest BlocksKit master. I'm not sure how to trap the error though. The debugger just sends me back to main() in main.m. Nor am I sure how to diagnose the issue.

Any ideas?

@zwaldowski
Copy link
Collaborator

Hm. How odd. I'll look into it.

@brspurri
Copy link
Author

Awesome. Thanks! I've tried it with both debuggers (not that I would expect that to make a difference). Both failed.
Let me know what additional information I could give you to help diagnose.

Thanks again. I'm pretty stuck without your help on this :-)

@zwaldowski
Copy link
Collaborator

Have you also pulled in the latest A2DynamicDelegate? That code snippet is working fine on my end. Also, could you try pulling open the stack trace as much as possible, as shown here?

@cyrille-legrand
Copy link

Same one here:

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req];
[conn setFailureBlock:^(NSURLConnection *c, NSError *e) {
    _status = statusErrorVersion;
    [self update];
}];

Fails on the setFailureBlock: telling me that it's an unrecognized selector.

Compiling with iOS 5.1 SDK, latest BlocksKit and A2DynamicDelegate (pulled right now). I can't expand the stack trace more.

@cyrille-legrand
Copy link

Solved right now by patching NSURLConnection+BlocksKit.m with the following:

225c225
<   void (^block)(NSURLConnection *, NSError *) = [self blockImplementationForMethod:_cmd];
---
>   void (^block)(NSURLConnection *, NSError *) = connection.failureBlock;
234a235
> static NSString *const kFailureBlockKey = @"NSURLConnectionDidFailWithError";
295a297,307
> - (void(^)(NSURLConnection *, NSError *))failureBlock {
>     return [[self.dynamicDelegate handlers] objectForKey:kFailureBlockKey];
> }
> 
> - (void)setFailureBlock:(void (^)(NSURLConnection *, NSError *))block {
>     if (block)
>       [[self.dynamicDelegate handlers] setObject:block forKey:kFailureBlockKey];
>     else
>       [[self.dynamicDelegate handlers] removeObjectForKey:kFailureBlockKey];
> }
> ```

@xNekOIx
Copy link

xNekOIx commented Jul 27, 2012

Hi. I have got issue with NSURLConnection too.
The exception was:
[NSURLConnection setFailureBlock:]: unrecognized selector sent to instance
Also i have met similar issue for [UIAlertView showAlertViewWithTitle:message:cancelButtonTitle:otherButtonTitles:handler:]
The exception was:
[UIAlertView setDidDismissBlock:]: unrecognized selector sent to instance
Both issues appeared only in release build. In debug mode all things were going well.

@digal
Copy link

digal commented Sep 26, 2012

Same problem with release builds. Dynamic delegates (at least, NSUrlConnection, UIAlertView, UIActionSheet) seem to be broken in the appstore version.

Is it related to compiler optimisations in 'release' config?

@digal
Copy link

digal commented Sep 26, 2012

This bug in A2DynamicDelegate seem to be related: pandamonia/A2DynamicDelegate#9
In this case, upgrading to BlocksKit 1.5.2 and A2D 2.0.2 should solve the problem.

Upd: no, it doesn't, at least for NSUrlConnection)

@a2
Copy link
Collaborator

a2 commented Jun 26, 2013

Just checking in. Is this still an issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants