iphone - asi-http-request asynchronous selector error -


i keep getting weird error when using asi-http-request when use selectors register callbacks success , failure.

the following methods used:

//  sets request , takes care of stuff needs each //  , every request. - (void) setup:(nsstring *) fragment successcallback:(sel) success_callback failurecallback:(sel) failure_callback {    //  convert string url   nsstring *url = [[nsstring alloc] initwithformat:@"%@%@",     self.server.serverurl,     fragment   ];   nsurl *full_url = [nsurl urlwithstring: url];    //  time setup 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 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 input 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 , failure callbacks

- (void) registersuccess: (asihttprequest *) request {     nsstring *response = [request responsestring];     nslog(@"response string: %s", response); }  // called when http request fails. means not // reach server unknown reason. - (void) registerfailure: (asihttprequest *) request {     nserror *error = [request error];     nslog(@"register error: %s", [error localizedfailurereason]); } 

i invoke register method 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 , error gdb:

2010-12-02 12:33:56.889 projectprototype[2201:6003] -[__nscftype absoluteurl]: unrecognized selector sent instance 0x6457c60 2010-12-02 12:33:56.891 projectprototype[2201:6003] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscftype absoluteurl]: unrecognized selector sent instance 0x6457c60' *** call stack @ 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 instance of 'nsexception' 

i appreciate , help, alot :)~

dudester have 2 serious syntax priblems:

first, each use of incorrect:

self.currequest 

the first time only set request, use self.request = blah.

after that, use [currequest xyz]

second serious problem,

[self.currequest setdidfailselector:success_callback]; [self.currequest setdidfinishselector:failure_callback]; 

you forgot 'selector' bit, should more this:

[request setdidfinishselector:@selector(blahcommuniquedone:)]; [request setdidfailselector:@selector(blahcommuniquedoneproblem:)]; 

(be careful colons, also.) forget trying pass them in sels. 2 routines right there in same object. point them.

here's typical complete working example. if follow you'll have no problems. these 3 routines sit in same file.

-(void) blahcommunique     {     // sends string blah pid (even if blank)     // v5 sends blah ..      nsurl *url = [nsurl urlwithstring:@"https://blah?blah"];     asiformdatarequest *request = [asiformdatarequest requestwithurl:url];      [request setpostvalue:blahaa forkey:@"blahaa"];     [request setpostvalue:blahbb forkey:@"blahbb"];// new in v5      [request setpostvalue:simplestringthisversion forkey:@"version"];  #define qq(a) [nsstring stringwithformat:@"%d", a]      [request setpostvalue:qq(vfourblahcount) forkey:@"cr"];     [request setpostvalue:qq(vfourblahcount) forkey:@"sb"];     [request setpostvalue:qq(vfourblahcount) forkey:@"so"];     [request setpostvalue:qq(vfourblahcount) forkey:@"lc"];     [request setpostvalue:qq(oldlaunchcount) forkey:@"olc"];  #undef qq      [request setpostvalue:[[nslocale preferredlanguages] objectatindex:0] forkey:@"langpref"];      [request setdelegate:self];     [request setdidfinishselector:@selector(statscommuniquedone:)];     [request setdidfailselector:@selector(statscommuniquedoneproblem:)];      [request startasynchronous];     }  -(void) statscommuniquedone:(asihttprequest *)request     {     nsdata *newstringdata = [request responsedata];//todo, check [incomingfloatdata length]      self.factorymessageifany =         [[[nsstring alloc] initwithdata:newstringdata encoding:nsutf8stringencoding] autorelease];      if ( [self.factorymessageifany isequaltostring:@"ok"] )         self.factorymessageifany = @"";     } -(void) statscommuniquedoneproblem:(asihttprequest *)request     {     // statscommuniquedoneproblem ... !     self.factorymessageifany = @"";     } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -