Common troubleshooting questions for iOS developers using the DataCenter component in mPaaS.
How do I use a DataCenter API to set the storage directory?
DataCenter organizes stored data by user ID. Call setCurrentUserId: to point DataCenter to the correct database whenever the active user switches. Call this before any business layer reads or writes data.
[[APDataCenter defaultDataCenter] setCurrentUserId:userId];
On sign out, you do not need to clear the user ID. DataCenter continues using the database of the last active user.
How do I set the default encryption key?
DataCenter encrypts data by default. If you do not provide a key, DataCenter derives one from appKey (passed to mPaasInit), which is secure. For stronger control, supply your own 32-byte key.
Enabling
Implement appDataCenterDefaultCryptKey in the mPaasAppInterface API to return the key as NSData:
#pragma mark DataCenter
/**
* If you implement this method, return the default encryption key (32 bytes) used by DataCenter.
* You can manage this key with Security Guard, or encrypt and obfuscate it before writing it to the client.
* If you do not implement this method, DataCenter uses a key derived from mPaaS and appKey, which is also secure.
*
* @return The 32-byte key stored in NSData.
*/
- (NSData*)appDataCenterDefaultCryptKey;
Persisting
Generate a 32-byte key, encode it as a Base64 string, and store it in Security Guard. At runtime, retrieve and parse it into NSData using a Security Guard static API.
Is DataCenter thread-safe?
Yes. All public DataCenter storage APIs are thread-safe and can be called from any thread without additional synchronization.
How do I resolve the conflict with the Baidu Maps SDK?
Integrating certain versions of the Baidu Maps SDK causes a crash at app startup.

Add the following code during app initialization. Requires mPaaS 10.1.32 or later.
#import <MPDataCenter/APDataCenter.h>
// Add the following code to the app initialization method.
APDataCenter.compatibility = YES;
How does archiveObject store and read variables?
Use APUserPreferences to persist and retrieve objects with archiveObject.
-
Store the object:
MPCodingData *obj = [MPCodingData new]; obj.name = @"Amelia"; obj.age = 1; [APUserPreferences archiveObject:obj forKey:@"archObjKey" business:dataBusiness];
Read it back from DataCenter:
MPCodingData *encodeObj = [APUserPreferences objectForKey:@"archObjKey" business:dataBusiness];