Managing Stores

If you create global stores, you’re required to perform cleanup when the app exits. Also, if you create multiple user stores, you can perform cleanup if you’re no longer using particular stores. SmartStore provides methods deleting named and global stores. For hybrid apps, SmartStore also provides functions for getting a list of named stores.

iOS Native Apps

Mobile SDK for iOS defines the following SFSmartStore methods for removing stores.

Swift

func removeShared(withName: String) -> Void
func removeShared(withName: String, forUserAccount: UserAccount) -> Void
func removeSharedGlobal(withName: String) -> Void
func removeAllForCurrentUser() -> Void
func removeAll(forUserAccount: UserAccount) -> Void
func removeAllGlobal() -> Void

Objective-C

+ (void)removeSharedStoreWithName:(NSString *)storeName;
+ (void)removeSharedStoreWithName:(NSString *)storeName forUser:(SFUserAccount *)user;
+ (void)removeSharedGlobalStoreWithName:(NSString *)storeName;
+ (void)removeAllStores;
+ (void)removeAllStoresForUser:(SFUserAccount *)user;
+ (void)removeAllGlobalStores;

In addition, SmartStore provides the following methods for retrieving store names. Use this method for both Swift and Objective-C apps.

+ (NSArray *)allStoreNames;
+ (NSArray *)allGlobalStoreNames;

Android Native Apps

Mobile SDK for Android defines the following SmartStoreSDKManager methods for removing stores.

public void removeGlobalSmartStore(String dbName)
public void removeSmartStore()
public void removeSmartStore(UserAccount account)
public void removeSmartStore(UserAccount account, String communityId)
public void removeSmartStore(String dbNamePrefix, UserAccount account, String communityId)

In addition, SmartStore provides the following methods for retrieving store names.

public List<String> getGlobalStoresPrefixList()
public List<String> getUserStoresPrefixList()

Hybrid Apps

SmartStore defines the following functions for removing stores. Each function takes success and error callbacks. The removeStore() function also requires either a StoreConfig object that specifies the store name, or just the store name as a string.

removeStore(storeConfig, successCB, errorCB);
removeAllGlobalStores(successCB, errorCB);
removeAllStores(successCB, errorCB);

In addition, the hybrid version of SmartStore provides the following functions for retrieving the StoreConfig objects for defined stores.

getAllStores(successCB, errorCB);
getAllGlobalStores(successCB, errorCB);
getAllStores(successCB, errorCB);
getAllGlobalStores(successCB, errorCB);

Removing All SmartStore Data at Runtime

Sometimes an app must remove all data in a store without logging out the current user. In this case, keep in mind that the sync manager object sets up a table to track syncs. If you delete this table, the manager can’t continue. Therefore, the recommended way to reset SmartStore to a zero-data state is as follows:

1. Drop the sync managers associated with the current user.

iOS

Swift

Call the following SyncManager method:

func removeSharedInstance(user: UserAccount) -> Void

Objective-C

Call the following SFMobileSyncSyncManager method:

+ (void)removeSharedInstance:(SFUserAccount*)user;

Android

Call the following MobileSyncSyncManager method:

public static synchronized void reset(UserAccount account)

2. Drop the stores associated with the current user.

iOS

Swift

Call the following SmartStore method:

func removeAll(forUserAccount: UserAccount) -> Void

Objective-C

Call the following SFSmartStore method:

+ (void)removeAllStoresForUser:(SFUserAccount *)user;

Android

Call the following SmartStoreSDKManager method:

public void removeAllUserStores()