Question

I am using multipeer connectivity to send a file on bluetooth. The progress is stored in a variable called Progress:

NSProgress* progress;

and it is accessed in this way:

progress.fractionCompleted

How can I call a method to update my UIprogressBar when the number changes?

There is a method:

-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress

{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);

}

But it is called only once...

Was it helpful?

Solution

You can use KVO on fractionCompleted something like that

    [_progress addObserver:self 
        forKeyPath:@"fractionCompleted" 
           options:NSKeyValueObservingOptionNew 
           context:NULL];

Then override 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];
}

You can check Matt blog for more details http://www.raywenderlich.com/49850/whats-new-in-objective-c-and-foundation-in-ios-7

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top