Alessandro
Alessandro

Reputation: 4110

MCSession multipeer in background

I am sending through multi peer in ios7 a file using this method:

_progressSend = [session sendResourceAtURL:imageUrl withName: info toPeer:peerID withCompletionHandler:^(NSError *error) {
    // Implement this block to know when the sending resource transfer completes and if there is an error.
    if (error) {
        NSLog(@"Send resource to peer [%@] completed with Error [%@]", peerID.displayName, error);
    }
    else {
        // Create an image transcript for this received image resource

    }
}];

The problem is very strange. This is what happens:

The device starts sending the resource, the progress bar starts filling up. When I put the app in the background, and check my email for example, the transfer is still going on (I can see that from the progress bar of the other device). If the transfer has finished, and I go back in the app, everything works just fine, but if I enter the app while the resource is still being transferred (for e.g. I exit 1/3 of the way and open it at 2/3) the app freezes completely and needs to be closed from the multitask bar. But Xcode doesn't show a crash. It is as iff the app keeps running but the user interface is just totally frozen. Does anyone have an idea??

Upvotes: 0

Views: 986

Answers (2)

user3001058
user3001058

Reputation: 13

I had this issue also in a different type of way. On the portion of code that updates the progress bar you need to make it call the main thead by putting the code inside this block:

dispatch_async(dispatch_get_main_queue(), ^{  
//insert progress bar code here
});

I don't know why this happens but this seems to have fixed it for me.

Upvotes: 0

user2952366
user2952366

Reputation: 11

Have you tried wrapping your code that sends the data in a dispatch_async block? That might help. Also how do you get the imageurl? Maybe it somehow can't be read when leaving and then re-entring you app

Upvotes: 1

Related Questions