After adding the MSS SDK, project configuration is required before using the SDK.
Note As of June 28, 2020, mPaaS no longer maintains the 10.1.32 baseline. Use the 10.1.68 or 10.1.60 baseline series instead. To upgrade your baseline, see the mPaaS 10.1.68 Upgrade Guide or mPaaS 10.1.60 Upgrade Guide. |
Prerequisites
Ensure that you use SDK version 10.1.32 or later.
You can find the current SDK version in the mpaas_sdk.config file.

Configure the project
Ensure that the meta.config file is in your project. This file contains configuration information, such as the Sync service endpoint and port.
If you use the latest plug-in to add the Sync SDK, this file is generated automatically.
If the
meta.configfile does not exist in your project,Go to the Console > Code Management > Code Configuration page to download the
.configconfiguration file. Then, rename the file tometa.configand add it to your project.
Notes for upgrading from an earlier version
Versions later than 10.1.32 do not require the Category file for the DTSyncInterface class. Instead, the middle layer reads the configuration from the meta.config file. After you upgrade, check your project for legacy configurations and remove them.

Code example
To listen for synchronization events, create a class. A RAM-resident service is best for continuously listening for Sync messages. In the following example, a MySyncService class is created to listen for synchronization events.
Before listening for synchronization events, define a business identity name. This name corresponds to the synchronization configuration identity in the data synchronization console. This parameter identifies your client to the service. In the following example, the business identity name is SYNC-TRADE-DATA.
#import <MPMssAdapter/MPSyncInterface.h>
#define SYNC_BIZ_NAME @"SYNC-TRADE-DATA"
@implementation MySyncService
+ (instancetype)sharedInstance
{
static MySyncService *bizService;
static dispatch_once_t llSOnceToken;
dispatch_once(&llSOnceToken, ^{
bizService = [[self alloc] init];
});
return bizService;
}
-(instancetype)init
{
self = [super init];
if (self) {
[MPSyncInterface initSync];
BOOL registerSingleDeviceSync = [MPSyncInterface registerSyncBizWithName:SYNC_BIZ_NAME syncObserver:self selector:@selector(revSyncBizNotification:)];
[MPSyncInterface bindUserWithSessionId:@"SESSION_DEMO"]; // The User corresponds to the userId required when sending commands from the console, and must match the value in the MPaaSInterface userId function. The sessionId is the client's authorization token. Both userId and sessionId are returned on user logon. If either value changes, call this function again to re-establish the persistent connection.
}
return self;
}
-(void)revSyncBizNotification:(NSNotification*)notify
{
NSDictionary *userInfo = notify.userInfo;
dispatch_async(dispatch_get_main_queue(), ^{
// Process the business data
[MySyncService handleSyncData:userInfo];
// Callback to the Sync SDK to indicate that the business data is processed.
[MPSyncInterface responseMessageNotify:userInfo];
});
}
+(void)handleSyncData:(NSDictionary *)userInfo
{
NSString * stringOp = userInfo[@"op"];
NSArray *op = [NSJSONSerialization JSONObjectWithData:[stringOp dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
if([op isKindOfClass:[NSArray class]]){
[op enumerateObjectsUsingBlock:^(NSDictionary * item, NSUInteger idx, BOOL *stop) {
if([item isKindOfClass:[NSDictionary class]]){
NSString * plString = item[@"pl"];// Business data payload
if(item[@"isB"]){
NSData *dataPl = [[NSData alloc] initWithBase64EncodedString:plString options:kNilOptions];
NSString *pl = [[NSString alloc] initWithData:dataPl encoding:NSUTF8StringEncoding];
NSLog(@"biz payload data:%@,string:%@",dataPl,pl);
}else{
NSLog(@"biz payload:%@",plString);
}
}
}];
}
}
-(void)dealloc
{
BOOL unRegisterSingleDeviceSync = [MPSyncInterface unRegisterSyncBizWithName:SYNC_BIZ_NAME syncObserver:[MySyncService sharedInstance]];
[MPSyncInterface removeSyncNotificationObserver:self];
}
@end