Parse saveEventually saves an empty object

When I try to save PFObject without a network connection, it is successfully saved locally, whenever I run the application again with a network connection, it seems that the object will be saved on the server, but all the parameters are empty.

I perform the following procedure: first I create a PFObject with different values ​​and call saveEventually . During these steps, I do not have an Internet connection (airplane mode is on), so it cannot be saved on the server and saved locally.

 PFObject *contact = [PFObject objectWithClassName:@"Contact"]; [contact setObject:[PFUser currentUser] forKey:kRelatedToUserKey]; [contact setObject:self.firstname forKey:kFirstnameKey]; [contact setObject:self.lastname forKey:kLastnameKey]; [contact saveEventually]; 

Now I close the application and start it again, I download such contacts. I am returning the correct object with all the correct value for firstname, lastname, etc.

 PFQuery *postQuery = [PFQuery queryWithClassName:@"Contact"]; [postQuery whereKey:@"related_to_user" equalTo:[PFUser currentUser]]; [postQuery fromLocalDatastore]; [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // here I get back the correct object from local storage, with all values } }]; 

Now, when I turn off airplane mode, it tries to save the object to the server, but all I can see in the backend is an object without any values.

enter image description here

Whereas a locally stored object has all the correct values.

+5
source share
4 answers

This bug is now fixed in Parse version 1.6.3!

0
source

So what are you trying to do for sure? Here's how he reads:

Your request for the Contact class, and after requesting it and searching for an object by its identifier (an object that you do nothing with [ PFObject *contact ]), you create PFObject for a completely different class ?? You could get around all this if you just want to send a PFObject message, but maybe you omitted another code that is not relevant to the question? But good. To answer your question, saveEventually works hand in hand with a local data store, so you should not have any problems, as you can see, it is called, but your values ​​are not saved, like objectID. The ID object is created autonomously, so it is saved and nothing else. I literally tried to duplicate your mistake in all possible ways, but I can’t, these are your values, they return zero. I even used macros (it seems that this is what your settings are like your keys), emulated flight mode, etc. To check, request your pinned object and see what it returns. Also, it is best when you call back to try to include an if statement or a switch statement that explains it explicitly for best practice:

 { if (succeeded) { debt.parseID = newDebt.objectId; }]; }]; 

In addition, be careful to put important tasks into the success block, because an important element of saveEventually is that if it does not finish before the application is completed, and if the object is still in memory, it will try again. but if the object is no longer in memory, it will try to execute the next execution sequence again, but WITHOUT a success block.

Eliminate your property values ​​(self.contact | self.amount | self.incomingDebt) as you define these


We have come a long way from the original message, so to try to get it back, the real and only problem here is saveEventually .

Stores this object on the server at some indefinite time in the future, even if Parse is currently unavailable.

The main purpose of saveEventually :

Use this when you may not have a solid network connection and don’t need to know when the save is complete

If it is expected that more than 10 MB of data will be sent, subsequent calls will be disconnected, and the old ones will be saved until the connection is restored and the objects in the queue can be saved.

You have no control over when this is caused. In addition, persistence ultimately caches data on the local disk until it is successfully loaded, so binding to the same object is redundant. Saving in the end, if you think about it, is a local data storage, it stores them on a local disk until the Internet is available (local data storage)

You have two ways around this. Local data storage is a kernel and data feature that allows users to opt out of NSFRC with a simple single-line pin/pinInBackground: code. You can simply bind objects, and when you find out that the Internet is disconnected again and stored on your server. Alternatively, you could do it differently, immediately achieve reachability, and if there is no Internet pin: object, saveInBackground: Or just use their caching policies.


LINKS

+1
source

It was an error in sdk. (1.6.2)

Presented here: https://developers.facebook.com/bugs/1554492594835537/

+1
source

I had a similar problem, I really found that removing or missing a call [Parse enableLocalDatastore]; led to the execution of saveEventually as expected (using Parse 1.6.2). I suggested that this would require [Parse enableLocalDatastore]; .

0
source

Source: https://habr.com/ru/post/1211204/


All Articles