受信中のファイルの進行状況を追跡するために KVO を使用しています。
-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress
{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);
dispatch_sync(dispatch_get_main_queue(), ^{
[progress addObserver:self
forKeyPath:@"fractionCompleted"
options:NSKeyValueObservingOptionNew
context:NULL];
});}
と
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == progress) {
// Handle new fractionCompleted value
[progressBar setProgress:progress.fractionCompleted animated:YES];
NSLog(@"Fraction Complete: %@", [NSNumber numberWithDouble:progress.fractionCompleted]);
return;
}
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
}
これを使用して UIprogressView を更新したいと思います...しかし、コードはこの行でクラッシュしており、理由がわかりません:
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
編集:
これがエラーです
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<ViewController1: 0x15b57000>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
編集:
スーパーobserveValueForKeyPath:keyPath...を削除すると、アプリはクラッシュしませんが、NSLog(@"Fraction Complete: %@ は常に値「0」を報告します。