我建議使用Couchbase-lite API來清除由Couchbase-lite本身創建的所有數據。您可以使用其他(取決於您如何/在何處存儲此數據)方法來清除註銷時的其他用戶數據。
如果您只想刪除爲用戶創建的所有數據庫,請詢問CBLManager
以獲取所有數據庫名稱。
/** An array of the names of all existing databases. */
@property (readonly) CBLArrayOf(NSString*)* allDatabaseNames;
而且你可以使用異步刪除每個數據庫:
[manager backgroundTellDatabaseNamed:self.database.name
to:^(CBLDatabase *db) {
NSError *error;
if (![db deleteDatabase:&error])
//bummer!
else
//success!
}];
如果你特別尋找一種方式來刪除文件,看看CBLDatabase
API本地文件的。
/** Deletes the local document with the given ID. */
- (BOOL) deleteLocalDocumentWithID: (NSString*)localDocID
error: (NSError**)outError ;
然而,這有不同的目的;在刪除數據庫之前,不需要刪除文檔。要清理註銷中的所有數據,只需刪除屬於用戶的所有數據庫。
此外,如果你還是堅持不使用CBL API,CBL文件存儲在默認目錄,可以通過CBLManager
/** The default directory to use for a CBLManager. This is in the Application Support directory. */
+ (NSString*) defaultDirectory;
獲得該路徑有沒有你不通過Couchbase打算這樣做的理由Lite API?爲什麼不直接從管理器獲取數據庫名稱列表,然後獲取每個數據庫名稱並在其上調用'delete'? – borrrden
感謝您的迴應,並且正如下面評論的那樣,當我在下班後回家後,最終做到了這一點。也適用於任何類似或可能更需要的人也如下所述。 cbl管理器有一個目錄方法,您可以使用DirectoryEnnumerator和filemanager清除以及其他包含文件夾的應用程序。 – thekevshow