我遇到了随机崩溃,我没有任何信息。崩溃Xcode告诉我这个:
或者:
所有离开应用程序的连接都是从NSObject类运行的,代码是:
·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];
for (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
问题可能源于同时启动更多连接的事实?
大多数连接都脱离后台线程
修改
我已经改变了:
@property (nonatomic, strong) id <LoadMysqlDelegate> delegate;
使用:
@property (nonatomic, weak) id <LoadMysqlDelegate> delegate;
但问题仍然存在。
编辑2
我终于有了完整的堆栈跟踪: