0
votes

I am using anonymous users in parse and if they are not saved, I issue a network call to save them. The code for saving the user is as follows

PFUser* current = [PFUser currentUser];
if (!current.objectId) {
    // The user is newly created, don't run any queries for them until they are saved.
    [current saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        // We need a saved user to do stuff.
        if (!succeeded) {
            NSLog(@"Error saving user: %@", error);
        } else {
            NSLog(@"Saved anonymous user");
            // ... load data
        }
    }];
    return;
}

If I run this in the simulator with no internet connection, the save fails (clearly), but succeeded is true and error is nil, so my code goes into loading data even though the user was not saved. In fact the error gets logged in logs but isn't returned in the callback:

Error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x17aa1220 {NSErrorFailingURLStringKey=https://api.parse.com/2/user_signup_or_login, NSErrorFailingURLKey=https://api.parse.com/2/user_signup_or_login, NSLocalizedDescription=The Internet connection appears to be offline., NSUnderlyingError=0x1792c880 "The Internet connection appears to be offline."} (Code: 100, Version: 1.2.20)

Is this a bug in the Parse API or am I not using something correctly?

3
This was a bug which has now been fixed in the latest release of parse. - Kostub Deshmukh

3 Answers

0
votes

It is not enough to just check the succeeded flag, you should also check the error.

If you are only going to check one of them, check the error.

The following is the pattern I would use:

if (succeeded && !error) {
    // success!
} else {
    // uh oh :(
}
0
votes

You can handle the error in the else block by using kPFErrorConnectionFailed which checks for connection.

Example

else { 
       if(error.code == kPFErrorConnectionFailed) 
        {
           // handle error 
        } 

    }
0
votes

This was a bug which has now been fixed in the latest release of parse.