How to reset PFInstallation

Is there a way to reset PFInstallation?

Here is a possible problematic scenario on my app:

  1. PFInstallation.current() created a record on the Installation table correctly
  2. Based on PFInstallation.current() and the installationId cached, we use cloudcode to trigger some actions. I.e. search for installation and add/remove custom subscription information into a column in that installation row.
  3. Imagine a situation where that installation row is accidentally removed
  4. PFInstallation.current() remains unchanged on the client’s phone, it is still sending the old installation ID to the server.
  5. The server throws Object not found exception as it cant find the installation object
  6. The app stucks in error mode forever, even if killed and restarted
  7. The only way for the client’s app to work again is to completely uninstall and reinstall the app again

Is there a way to reset/clear cache/delete PFInstallation.current()?

I found one relevant discussion here, but it feels like a hack.

We could assume that the client should always have the authority over the installation ID. After all its the client who creates the installation ID in the first place and tells it to the server. That would mean:

  • The server needs to create an installation object if there isn’t one.
  • The client must not try to invent a new installation ID but use the existing one, because the truth is that the installation is still the same, so it should have the same ID. The ID may also be referenced somewhere else, outside of the installation object that got deleted.

It looks as if the client gets stuck because the client tries to update an installation object that doesn’t exist. (Could you verify this sever side?)

If so, the solution could be that the client should request an upsert when creating / updating an installation. Technically, a server-side fix could also be to create an installation if updating fails because the object doesn’t exist, but that would likely violate the expected REST behavior, which differentiates between a POST (insert) and a PUT (upsert).

We’d need to look on whether Parse Server supports PUT or what else it’s using for an upsert.

A quick workaround could be to use a Cloud Code trigger to create the installation object in case it doesn’t exist.

For the cloud code to re-create the missing installation, the cloud code has to specify a specific objectId/installationId?

I would look at the incoming request from the SDK and from that recreate the installation.