Ale*_*dro 2 ios multipeer-connectivity
我使用多重连接在蓝牙上发送文件.进度存储在名为Progress的变量中:
NSProgress* progress;
并以这种方式访问它:
progress.fractionCompleted
当数字发生变化时,如何调用方法来更新我的UIprogressBar?
有一种方法:
-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress
{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);
}
但它只被召唤一次......
你可以在fractionCompleted这样的东西上使用KVO
    [_progress addObserver:self 
        forKeyPath:@"fractionCompleted" 
           options:NSKeyValueObservingOptionNew 
           context:NULL];
然后覆盖observeValueForKeyPath
    - (void)observeValueForKeyPath:(NSString *)keyPath 
                          ofObject:(id)object 
                            change:(NSDictionary *)change 
                           context:(void *)context
    {
        if (object == _progress) {
            // Handle new fractionCompleted value
            return;
        }
    [super observeValueForKeyPath:keyPath 
                     ofObject:object 
                       change:change 
                      context:context];
}
您可以查看Matt博客了解更多详情 http://www.raywenderlich.com/49850/whats-new-in-objective-c-and-foundation-in-ios-7