ios - NSProgress::completedUnitCount setter 挂起

标签 ios uikit nsprogress

  • (void)URLSession:(NSURLSession *)session 任务:(NSURLSessionTask *)任务 didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend { self.progress.completedUnitCount = totalBytesSent; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^这卡在ios 9.0上 对此有什么想法吗???

  • (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend;在主线程上调用并不重要

(lldb) BT * thread #1: tid = 0xd6e1, 0x00000001984a0c6c libsystem_kernel.dylibsemaphore_wait_trap + 8, queue = 'com.apple.main-thread', activity = 'send control actions', 1 条消息, stop reason = signal SIGSTOP * 帧 #0:0x00000001984a0c6c libsystem_kernel.dylibsemaphore_wait_trap + 8 第 1 帧:0x000000019857a97c libsystem_platform.dylib_os_semaphore_wait + 24 帧 #2:0x00000001007bd428 libdispatch.dylib_dispatch_barrier_sync_f_slow + 600 第 3 帧:0x00000001835af270 Foundation-[NSConcreteObservationBuffer _receiveBox:] + 248 帧 #4:0x00000001836180b0 基金会_NSKVO1AdaptorDeliver + 388 第 5 帧:0x0000000183617ea0 Foundation_NSKVO1AdaptorSlowDeliver + 264 第 6 帧:0x0000000183523b84 Foundation-[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 424 第 7 帧:0x00000001834ffdd4 FoundationNSKeyValueNotifyObserver + 304 第 8 帧:0x00000001834ff8fc 基金会NSKeyValueDidChange + 404 第 9 帧:0x00000001834ea114 Foundation-[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 120 第 10 帧:0x000000018258fab0 CoreFoundation__53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 132 第 11 帧:0x000000018258f9a8 CoreFoundation-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308 第 12 帧:0x00000001836cc158 基础-[NSProgress _setValueForKeys:settingBlock:] + 600 第 13 帧:0x00000001836cc87c Foundation`-[NSProgress setCompletedUnitCount:] + 124

PS:如果我避免将 UIProgressView::observedProgress 设置为那个 NSProgress,它工作正常!?

最佳答案

忙等待解决

-(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

关于ios - NSProgress::completedUnitCount setter 挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34590115/

相关文章:

ios - 如何向 iOS 中的所有 Controller 发送通知

ios - 在 iOS 8 上自定义 UISegmentedControl

swift - 使用 AFNetworking 快速下载文件

ios - NSProgress 奇怪的行为

iOS 将 subview 添加到具有动态高度的 ScrollView

ios - 如何在我的应用程序设置之上(之下)显示定位服务设置

ios - 如何计算具有右/左详细样式的 tableviewcell 的高度?

iphone - 在一个 UIViewController 中处理多个 UITableView 的最佳方法?

ios - 如何实现 3D-Touch Peek-and-select?

swift - 如何快速将属性观察器添加到 NSProgress?