iOS-Bug: NSRunloop Mode

来源:互联网 发布:matlab迭代解方程算法 编辑:程序博客网 时间:2024/05/16 15:31

static NSString *CNSDataRunloopMode = @"CNSDataRunloppMode";@implementation CNSData{    NSURLConnection *_connection;    NSString *_runLoopMode;}@synthesize data = _data;@synthesize finished = _finished;- (id)initWithUrl:(NSURL *)url {    self = [super init];    if (self) {        _data = [NSMutableData data];        _runLoopMode = CNSDataRunloopMode;        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];        [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];        _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];        [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:_runLoopMode]; //mark        [_connection start];        while (!self.finished) {            [[NSRunLoop currentRunLoop] runMode:_runLoopMode beforeDate:[NSDate distantFuture]]; //mark        }    }    return self;}


wrong:

static NSString *CNSDataRunloopMode = @"CNSDataRunloppMode";@implementation CNSData{    NSURLConnection *_connection;    NSString *_runLoopMode;}@synthesize data = _data;@synthesize finished = _finished;- (id)initWithUrl:(NSURL *)url {    self = [super init];    if (self) {        _data = [NSMutableData data];        _runLoopMode = CNSDataRunloopMode;        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];        [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];        _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];             while (!self.finished) {            [[NSRunLoop currentRunLoop] runMode:NSDefaultMode beforeDate:[NSDate distantFuture]];        }    }    return self;}


0 0
原创粉丝点击