All Products
Search
Document Center

Mobile Platform as a Service:Custom storage

Last Updated:Apr 13, 2023

The default storage space of APDataCenter is the /Documents/Preferences directory of the application sandbox. If the business is independent or the data amount is large, you can customize the storage space.

You can create your own storage directory by using APCustomStorage. You can use all services provided by Datacenter in this directory, which is similar to the APDataCenter. For example, you can run the following code to create the Documents/Contact directory.

APCustomStorage* storage = [APCustomStorage storageInDocumentsWithName:@"Contact"];

The directory contains both commonPreferences which stores public data and userPreferences which stores user-related data. APCustomStorage is similar to APDataCenter, so you don’t have to pay attention to user switching.

API description

  • (instancetype)storageInDocumentsWithName:(NSString*)name;

    Create a custom storage with path as /Documents/name.

  • (id)initWithPath:(NSString*)path;

    This method is usually not used for creating a custom storage at any specified path. The storageInDocumentsWithName can be used instead. The APCustomStorage created with this interface should be held by the yourself. When multiple APCustomStorages share the same path, errors will occur.

  • (APBusinessPreferences*)commonPreferences;

    For the global storage objects irrelevant to users, access data by using the key-value method. Different from APDataCenter, for APCustomStorage, the business argument is not required for storing key-value data in the custom storage space of the business. Only the key is required.

  • (APBusinessPreferences*)userPreferences;

    For the global storage objects of login users, access data by using the key-value method. When the user is not logged-in, nil will be returned. Different from APDataCenter, for APCustomStorage, the business argument is not required for storing key-value data in the custom storage space of the business. Only the key is required.

  • (id)daoWithPath:(NSString*)filePath userDependent:(BOOL)userDependent;

    For more information, see description of the APDataCenter class.