views:

181

answers:

2

I'm uploading photos to Facebook from my iPhone application. I've got it working, except that sometimes, it returns "Unknown Error Occurred". I'm not sure what the problem is. This happens about 75% of the time.

Has anyone else encountered this?

A: 

Try it on the simulator and use an http debugger like Charles to see what is happening during the transfer and what the response is from Facebook.

apphacker
+1  A: 

Still not sure what was happening, but I solved the problem. Here's what I did:

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
    if ([error code] == 1 && [[request method] isEqualToString:@"photos.upload"]) {
        FBRequest *tryAgain = [FBRequest requestWithDelegate:self];
        [tryAgain call:[request method] params:[request params] dataParam:(NSData *)[request dataParam]];
    }   
}

Essentially, I just made it try again. Resending the same request didn't work (failed with an invalid signature), so I created a new request with the properties of the old one.

The nice thing about this is that it is sort of recursive: if the new request fails too, it will just keep trying. I hope I don't encounter any negative side-effects of that, though.

Jonathan Sterling
Be careful. If for whatever reason every request you send fails (intermittent network problems or no network at all, facebook servers too busy etc), your application hangs forever. You should limit the number of times you try sending a new request if the previous one fails to a reasonable number (say 3).
unforgiven
Very well put. I was contemplating something like that as well.
Jonathan Sterling