I keep getting a very weird error when using asi-http-request when I use selectors to register callbacks for success and failure.
The following methods are used:
// Sets up a request and takes care of the stuff that needs to be for each
// and every request.
- (void) setup:(NSString *) fragment successCallback:(SEL) success_callback failureCallback:(SEL) failure_callback {
// Convert the string to a url
NSString *url = [[NSString alloc] initWithFormat:@"%@%@",
self.server.serverUrl,
fragment
];
NSURL *full_url = [NSURL URLWithString: url];
// Time to setup the request
self.curRequest = [ASIFormDataRequest requestWithURL:full_url];
[self.curRequest setDelegate:self];
[self.curRequest setDidFailSelector:success_callback];
[self.curRequest setDidFinishSelector:failure_callback];
// If we're using iphone os version 4.0
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self.curRequest setShouldContinueWhenAppEntersBackground:YES];
#endif
// Clean up time!
[url release];
[full_url release];
}
The register method
- (void) register_user:(NSString *) email password:(NSString *) password confirmPassword:(NSString *) confirm_password successCallback:(SEL) success_callback failureCallback:(SEL) failure_callback {
[self setup:@"/users/register" successCallback:success_callback failureCallback:failure_callback ];
// Setup the input to the method [self.curRequest setPostValue:email forKey: @"email"]; [self.curRequest setPostValue:password forKey: @"password"]; [self.curRequest setPostValue:confirm_password forKey: @"confirm_password"];
NSLog(@"We got here yo :)~ %@ %@ %@", email, password, confirm_password);
[self.curRequest startAsynchronous]; }
Success and Failure Callbacks
- (void) registerSuccess: (ASIHTTPRequest *) request {
NSString *response = [request responseString];
NSLog(@"Response string: %s", response);
}
// Called when the http request fails. That means it could not
// reach the server for an unknown reason.
- (void) registerFailure: (ASIHTTPRequest *) request {
NSError *error = [request error];
NSLog(@"Register error: %s", [error localizedFailureReason]);
}
I invoke the register method like so:
[self.appdelegate.userModel register_user:self.emailAddress.text password:self.password.text confirmPassword:self.confirmPassword.text successCallback:@selector(registerSuccess:) failureCallback:@selector(registerFailure:) ];
The callstack and error from gdb:
2010-12-02 12:33:56.889 ProjectPrototype[2201:6003] -[__NSCFType absoluteURL]: unrecognized selector sent to instance 0x6457c60
2010-12-02 12:33:56.891 ProjectPrototype[2201:6003] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType absoluteURL]: unrecognized selector sent to instance 0x6457c60'
*** Call stack at first throw:
(
0 CoreFoundation 0x0292eb99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02a7e40e objc_exception_throw + 47
2 CoreFoundation 0x029306ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x028a02b6 ___forwarding___ + 966
4 CoreFoundation 0x0289fe72 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x02843b04 CFURLCopyAbsoluteURL + 100
6 CFNetwork 0x023fe5e8 _ZN11HTTPMessage10initializeEPK10__CFStringPK7__CFURLS2_ + 52
7 CFNetwork 0x023fe50c CFHTTPMessageCreateRequest + 80
8 ProjectPrototype 0x00011360 -[ASIHTTPRequest main] + 852
9 Foundation 0x000c83ca __NSThreadPerformPerform + 251
10 CoreFoundation 0x0290ffaf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
11 CoreFoundation 0x0286e39b __CFRunLoopDoSources0 + 571
12 CoreFoundation 0x0286d896 __CFRunLoopRun + 470
13 CoreFoundation 0x0286d350 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x02870614 CFRunLoopRun + 84
15 ProjectPrototype 0x00023b55 +[ASIHTTPRequest runRequests] + 173
16 Foundation 0x000b376c -[NSThread main] + 81
17 Foundation 0x000b36f8 __NSThread__main__ + 1387
18 libSystem.B.dylib 0x9689881d _pthread_start + 345
19 libSystem.B.dylib 0x968986a2 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
I appreciate any and all help, thanks alot :)~