ios - random crashes with NSURLConnection -
ios - random crashes with NSURLConnection -
i'm running random crashes have no info. when crash xcode show me this:
or this:
all connections depart app run nsobject class , code this:
.h
@protocol loadmysqldelegate <nsobject> @required -(void)loadmysql:(nsarray *)array; @end @interface loadmysql : nsobject <nsurlconnectiondatadelegate, nsurlconnectiondelegate> @property (nonatomic, strong) id <loadmysqldelegate> delegate; -(void)connectionmysqlwithnick:(nsstring *)nick; @end
.m
#import "loadmysql.h" @implementation loadmysql { nsmutablearray *_arrayp; nsmutabledata *_data; } -(void)connectionmysqlwithnick:(nsstring *)nick { _data = [[nsmutabledata alloc] init]; _arrayp = [[nsmutablearray alloc] init]; [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:yes]; nsstring *stringurl = [nsstring stringwithformat:@"http://www.bla.it/load.php?valnick=%@",nick]; nsurl *url = [nsurl urlwithstring:stringurl]; nsurlrequest *request = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalandremotecachedata timeoutinterval:50.0f]; nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:no]; [connection scheduleinrunloop:[nsrunloop mainrunloop] formode:nsdefaultrunloopmode]; [connection start]; } - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)aresponse { [_data setlength:0]; } -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [_data appenddata:data]; } -(void)connectiondidfinishloading:(nsurlconnection *)connection { id jsonobjects = [nsjsonserialization jsonobjectwithdata:_data options:nsjsonreadingmutablecontainers error:nil]; (nsdictionary *datadict in jsonobjects) { nsstring *stringi = [datadict objectforkey:@"name"]; nsstring *stringt = [datadict objectforkey:@"type"]; nsdictionary *_dict = [nsdictionary dictionarywithobjectsandkeys:stringi,@"name",stringt,@"type", nil]; [_arrayp addobject:_dict]; } [_delegate loadmysql:_arrayp]; [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no]; } @end
the problem may stem fact of starting more connection simultaneously?
the bulk of connections depart background thread
edit
i've changed:
@property (nonatomic, strong) id <loadmysqldelegate> delegate;
with:
@property (nonatomic, weak) id <loadmysqldelegate> delegate;
but problem persist.
edit 2
i have finish stack trace:
ios objective-c nsurlconnection
Comments
Post a Comment