首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSProgress::完全单位计数设置器挂起

NSProgress::完全单位计数设置器挂起
EN

Stack Overflow用户
提问于 2016-01-04 11:27:41
回答 2查看 422关注 0票数 1
  • (URLSession:(NSURLSession*)会话任务:(NSURLSessionTask*)任务didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent { self.progress.completedUnitCount = totalBytesSent;^(Int64_t)bytesSent totalBytesSent:(NSURLSessionTask*)任务didSendBodyData:(Int64_t)bytesSent totalBytesSent:(Int64_t)totalBytesSent{self.progress.completedUnitCount=totalBytesSent;
  • (URLSession)URLSession:(NSURLSession*)会话任务:(NSURLSessionTask*)任务didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent

(lldb) bt *线程#1: tid = 0xd6e1,0x00000001984a0c6c libsystem_kernel.dylibsemaphore_wait_trap + 8, queue = 'com.apple.main-thread', activity = 'send control actions', 1 messages, stop reason = signal SIGSTOP * frame #0: 0x00000001984a0c6c libsystem_kernel.dylibsemaphore_wait_trap +8帧#1: 0x000000019857a97c libsystem_platform.dylib_os_semaphore_wait + 24 frame #2: 0x00000001007bd428 libdispatch.dylib_dispatch_barrier_sync_f_slow + 600帧#3: 0x00000001835af270 Foundation-[NSConcreteObservationBuffer _receiveBox:] + 248 frame #4: 0x00000001836180b0 Foundation_NSKVO1AdaptorDeliver + 388帧#5: 0x0000000183617ea0 Foundation_NSKVO1AdaptorSlowDeliver + 264 frame #6: 0x0000000183523b84 Foundation-NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:+ 424帧#7: 0x0000000001834ffdd4基础NSKeyValueNotifyObserver + 304 frame #8: 0x00000001834ff8fc FoundationNSKeyValueDidChange+ 404框架#9: 0x00000001834ea114:0x000000018258f9a8 CoreFoundation-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308 frame #12: 0x00000001836cc158 Foundation-NSProgress _setValueForKeys:settingBlock:+ 600 frame #13: 0x00000001836cc87c Foundation`‘-NSProgress setCompletedUnitCount:+ 124

PS:如果我避免将UIProgressView::观测进度设置为那个NSProgress,那么它工作得很好!?

EN

回答 2

Stack Overflow用户

发布于 2016-01-04 12:29:34

忙着等待解决

代码语言:javascript
复制
-(void)showUploadingUI
{
myHardAssert([[NSThread currentThread] isMainThread], @"");
self.progressView.hidden = NO;
NSProgress *progress = urlsession.progress;
if( [self.progressView respondsToSelector:@selector(observedProgress)]) {
// this causes hang     self.progressView.observedProgress = progress;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    while(progress.completedUnitCount < progress.totalUnitCount) {
        dispatch_sync(dispatch_get_main_queue(), ^{
            self.progressView.progress = progress.fractionCompleted;
        });
        [NSThread sleepForTimeInterval:0.033];
    }
    dispatch_sync(dispatch_get_main_queue(), ^{
        self.progressView.progress = 1;
    });

……

副作用是ios <9的向后兼容性。

票数 1
EN

Stack Overflow用户

发布于 2018-02-05 18:23:45

男孩帮了我的忙。我的应用程序在增加Progress.completedUnitCount时冻结了。(在主线程上)我假设这会触发一个设置器,因为有一个副作用-移动进度条,这是做它的全部原因。

我的Swift 4解决方案是把电话包装成这样:

代码语言:javascript
复制
DispatchQueue.global(qos: .utility).async {
    self._decompressionProgress.completedUnitCount += 1
}

我还是不太明白为什么这样做..。和很多事情没什么不同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34590115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档