3

Is there any effective way to remove all document stores by the CBL in ios? I am having issues with this, alternatively if someone knows how to essentially make the app as if it were just installed that would be extremely helpful as well. We are trying to make sure our logout actually sets the app up as if you were opening it for the first time, so no data is persisted. I have tried a few things but to no avail, am I missing something? Many, many search results have resulted in very little help.

Also this does not work either (Is there any way to clear all data stored from the installation of app?)

I have also tried removing all files in the app home directory which works somewhat but causes issues that I am assuming are because that is not how things should be done. Is the documents folder where the data I am speaking of should be contained?

Thank you in advance.

Community
  • 1
  • 1
thekevshow
  • 774
  • 14
  • 36
  • Is there a reason you are doing this without going through the Couchbase Lite API? Why not just simply get the list of database names from manager, then get each one and call `delete` on it? – borrrden Oct 14 '15 at 04:02
  • Thanks for the response, and as commented below I did end up doing that when I got home from work, after reading more. Also for anyone with similar or potentially more needed as also stated below. The cbl manager has a directory method which you can clear out using DirectoryEnnumerator and filemanager to clear as well or similarly for other app containing folders. – thekevshow Oct 14 '15 at 05:57
  • @thekevshow me too facing somewhat same issue.I need to clear all the data on sign out.Ive tried deleting the database, closing the database everything.But still there is no luck, as I was getting the documents of previous logged in user.Can you please explain in detail what and all I need to do on Sign-out? – Shyam Mar 26 '18 at 09:47

1 Answers1

4

I recommend using Couchbase-lite API's to clear all the data that is created by Couchbase-lite itself. You could use other(depends on how/where you've stored this data) approaches to clear other user data on logout.

If you want to simply remove all databases created for the user, ask the the CBLManager for all database names.

/** An array of the names of all existing databases. */
@property (readonly) CBLArrayOf(NSString*)* allDatabaseNames;

And you could asynchronously delete each database using:

[manager backgroundTellDatabaseNamed:self.database.name
                                  to:^(CBLDatabase *db) {
                                    NSError *error;
                                    if (![db deleteDatabase:&error])
                                      //bummer!
                                    else
                                      //success!
                                  }];

If you are particularly looking for a way to delete documents, have a look at CBLDatabase API's on local documents.

/** Deletes the local document with the given ID. */
- (BOOL) deleteLocalDocumentWithID: (NSString*)localDocID
                             error: (NSError**)outError ;

However, this serves different purpose; you don't need to delete documents before deleting the database. To clean up all the data on logout, simply delete all databases that belongs to user.

Additionally, if you still insist on not using CBL API, CBL files are stored in default directory and that path can be obtained by CBLManager

/** The default directory to use for a CBLManager. This is in the Application Support directory. */
+ (NSString*) defaultDirectory;
Ajith Renjala
  • 4,934
  • 5
  • 34
  • 42
  • Thank you, I actually did end up doing that to clear the DB when I got home I read some docs to delete the database, of course as my question originally stated I actually go and clear out a bunch of folders, using DirectoryEnumerator's for the folders and filemanager(NSFilemanager). I needed to clear that potentially stored caches and other things from our application so we can have a clean logout of the application. Thank you for your response, verified I am clearing that aspect correctly thankfully. – thekevshow Oct 14 '15 at 05:55