繁体   English   中英

使用解析NSString进行非常长的加载

[英]Very long loading with parse NSString

我已经建立了一个UILabel,它从parse.com获取其内容。 一切正常,直到我启用飞行模式。 在加载标签的视图中,我得到了非常长的加载时间,控制台向我提供了该代码:

    2012-11-08 21:07:41.179 My App[5275:907] Warning: A long-running Parse operation is being executed on the main thread. 
 Break on warnParseOperationOnMainThread() to debug.
2012-11-08 21:07:41.231 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c2f00 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1e5c1d70 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14)
2012-11-08 21:07:41.232 My App[5275:907] Network connection failed. Making attempt 2 after sleeping for 1.287663 seconds.
2012-11-08 21:07:42.582 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c6f00 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1e5c6f40 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14)
2012-11-08 21:07:42.583 My App[5275:907] Network connection failed. Making attempt 3 after sleeping for 2.575326 seconds.
2012-11-08 21:07:45.215 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1f88bd90 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88c840 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14)
2012-11-08 21:07:45.216 My App[5275:907] Network connection failed. Making attempt 4 after sleeping for 5.150652 seconds.
2012-11-08 21:07:50.383 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1f88c310 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88b4a0 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14)
2012-11-08 21:07:50.384 My App[5275:907] Network connection failed. Making attempt 5 after sleeping for 10.301305 seconds.
2012-11-08 21:08:00.743 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c8160 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88e450 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14)

“ Es besteht anscheinend keine Verbindung zum Internet”表示没有与Internet的连接。

有办法解决吗?

谢谢

不要在主线程上进行网络连接-永远:)

dispatch_async一个块,仅在主线程上设置标签的文本。

- (void)doLongOperation:(id)someParam withCompletionHandler:(void (^)(NSString *newLabelString))completionHandler {
    dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSString *labelString = /*do call to parse OR any other long running operation*/

        if ( completionHandler ) {
            dispatch_async(dispatch_get_main_queue(), ^{
            completionHandler(labelString); 
        });
    });
}

// now in your main app call it
[self doLongOperation:nil /*we dont need anything here*/ withCompletionHandler:^(NSString *newLabelString) {
    self.label.text = newLabelString;
}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM