iOS-Bug: NSRunloop Mode
2014-04-10 14:12
495 查看
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;
}
@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; }
相关文章推荐
- IOS使用第三方字体
- Cover Flow基本原理及Tapku实现方法
- Ios17个常用代码整理
- ios -蓝牙开发
- Auto Layout on iOS Versions prior to 6.0 解决办法
- iOS开发:使用SOAP访问Web服务
- iOS如何对XML/SOAP文件进行解析
- IOS开发百度地图API-用点生成路线,导航,气泡响应
- IOS-webService
- iOS 5与iOS 6的 low-memory 处理
- [iOS]FMDB入门学习
- ios开发- 收集好用的例子
- 台式机bios参数说明
- iOS 保存CGRect,CGPoint到NSArray'的方法
- IOS7 兼容适配总结(一)
- ios--OpenCV--cvCompareHist使用直方图模型(CvHistogram)比对两张图片
- iOS强弱引用
- ios随笔
- iOS-Xcode必备插件XAlign:瞬间优化你的代码
- 电脑bios启动项快捷键大全(转)