Simperium and handling sync optionally

303 Views Asked by At

What is the best approach to handle syncing when the user can choose to enable or disable syncing whenever he wants?

Specifically I am currently having the problem that Simperium crashes after its instance have been deallocated. Consider the following scenario:

  1. Create database and insert some objects
  2. Create Simperium instance, sign in and sync all offline created objects
  3. Sign out (meaning releases the Simperium instance)
  4. Create some more objects

App now crashes with:

-[__NSCFString objectsShouldSync]: unrecognized selector sent to instance

where __NSCFString is some former object that already got released

I am using the current master branch.

2

There are 2 best solutions below

0
On BEST ANSWER

This is a common request, and the "iosupdate" branch has some changes that will help. You can see this GitHub issue for some guidance. To summarize (quoting the author of this question):

When initializing the simperium instance set the following properties:

self.simperium.authenticationOptional = YES;

This make a cancel button appear.

self.simperium.authenticationEnabled = NO;

This prevents the authentication dialog from popping up.

self.simperium.loginViewControllerClass = [LoginViewController class]; This drops in a custom subclass of SPLoginViewController to overwrite the cancel: message, otherwise you would not get feedback that the user canceled the dialog.

When the user hits a sign "Sign in" button, I set

self.simperium.authenticationEnabled = YES;

which causes the login controller to show up.

0
On

I know this is an old question, but I spent ages trying this and couldn't find any pointers anywhere so...

Above answer is correct but I found after setting

self.simperium.authenticationEnabled = YES;

I needed to add

[self.simperium authenticateIfNecessary];

to get the login view to appear.