iphone - Problem passing NSError back as a return parameter -


i having problem passing nserror object back. first line of code access object (in case, inserted nslog) causes "exc_bad_access".

is because not explicitly creating nserror object, rather getting 1 nsurlrequest , passing back? in particular function (downloadfile:), errors want retrieve other functions, create nserror on 2 other occasions in function.

any appreciated.

here offending code:

-(void)somecode { nserror *err = nil;  localpool = [[nsautoreleasepool alloc] init];  if (!iap) {     iap = [[inapppurchasecontroller alloc] init]; }  if (![self.iap downloadfile:@"xxxxx.plist" withremotedirectory:nil withlocaldelete:yes withcontenttype:@"text/xml" error:&err] ) {     //"exc_bad_access" on calling nslog on next line?      nslog(@"error downloading plist: %@", [err localizeddescription]);      [self performselectoronmainthread:@selector(fetchplistfailed:) withobject:err waituntildone:no];     [localpool drain], localpool = nil;     return no; } //removed remainder of code clarity.  [localpool drain], localpool = nil; return yes; }   -(bool)downloadfile:(nsstring *)filename withremotedirectory:(nsstring *)remotedirectory  withlocaldelete:(bool)withlocaldelete  withcontenttype:(nsstring *)contenttypecheckstring      error:(nserror **)error {  uiapplication *app = [uiapplication sharedapplication]; app.networkactivityindicatorvisible = yes;   nserror *localerror = nil;  nsautoreleasepool *localpool = [[nsautoreleasepool alloc] init];  nsstring *urlstring = [nsstring stringwithformat:@"http://xxxxx/%@", filename];  nslog(@"downloading file: %@", urlstring);  nsurl *url = [nsurl urlwithstring:urlstring];  nsurlrequest *req = [[nsurlrequest alloc] initwithurl:url];  nshttpurlresponse *response = nil;  nsdata *responsedata = [nsurlconnection sendsynchronousrequest:req returningresponse:&response error:&localerror];  [req release];  if (response == nil || localerror) {     nslog(@"error retrieving file:%@", [localerror localizeddescription]);     if (error != null) {         *error = localerror;         //this nslog call works fine.         nslog(@"error copied is:%@", [*error localizeddescription]);     }  [localpool drain], localpool = nil;  app.networkactivityindicatorvisible = no;   return no; }  //rest of function omitted simplicity. } 

i guess nserror object autoreleased , put on localpool. drained localpool, destroying nserror.

do need localpool in every method? if not, remove localpools.

also, looks forgot drain localpool in somecode. didn't copy it...

-(void)somecode {     nserror *err = nil;      localpool = [[nsautoreleasepool alloc] init];      if (!iap) {         iap = [[inapppurchasecontroller alloc] init];     }      if (![self.iap downloadfile:@"xxxxx.plist" withremotedirectory:nil withlocaldelete:yes withcontenttype:@"text/xml" error:&err] ) {              ....             [localpool drain], localpool = nil;             return no;     }     [localpool drain], localpool = nil; // missing } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -