(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 *)会话任务:(NSURLSessionTask *)任务 didSendBodyData:(的int64_t)bytesSent totalBytesSent:(的int64_t)totalBytesSent totalBytesExpectedToSend:(的int64_t)totalBytesExpectedToSend;在主线程上调用而不是它应该重要
(lldb)bt
* thread#1:tid = 0xd6e1,0x00000001984a0c6c libsystem_kernel.dylib semaphore_wait_trap + 8, queue = 'com.apple.main-thread', activity = 'send control actions', 1 messages, stop reason = signal SIGSTOP
* frame #0: 0x00000001984a0c6c libsystem_kernel.dylib
semaphore_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基金会-[NSConcreteObservationBuffer _receiveBox:] + 248
frame #4: 0x00000001836180b0 Foundation
_ NSKVO1AdaptorDeliver + 388
第5帧:0x0000000183617ea0基金会_NSKVO1AdaptorSlowDeliver + 264
frame #6: 0x0000000183523b84 Foundation
- [NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 424
第7帧:0x00000001834ffdd4基金会NSKeyValueNotifyObserver + 304
frame #8: 0x00000001834ff8fc Foundation
NSKeyValueDidChange + 404
帧#9:0x00000001834ea114基金会-[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 120
frame #10: 0x000000018258fab0 CoreFoundation
__ 53 - [__ NSArrayM enumerateObjectsWithOptions:usingBlock:] _ block_invoke + 132
帧#11:0x000000018258f9a8 CoreFoundation -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308
frame #12: 0x00000001836cc158 Foundation
- [NSProgress _setValueForKeys:settingBlock:] + 600
帧#13:0x00000001836cc87c基础`- [NSProgress setCompletedUnitCount:] + 124
PS:如果我避免将UIProgressView :: observedProgress设置为该NSProgress,它可以正常工作!?
答案 0 :(得分:1)
忙着等待解决
-(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的向后兼容性&lt; 9
答案 1 :(得分:0)
男孩帮了我。递增Progress.completedUnitCount
时我的应用程序冻结了。 (在主线程上。)我假设这触发了一个setter,因为有副作用 - 移动进度条,这是完成它的全部原因。
我的Swift 4解决方案就是这样打电话:
DispatchQueue.global(qos: .utility).async {
self._decompressionProgress.completedUnitCount += 1
}
我仍然不太明白为什么这样做......与许多事情不同。