All Products
Document Center

Mobile Platform as a Service:Use SDK

Last Updated:Jan 12, 2022

Important: Since June 28, 2020, mPaaS has stopped support for the baseline 10.1.32. Please use 10.1.68 or 10.1.60 instead. For how to upgrade the baseline from version 10.1.32 to 10.1.68 or 10.1.60, see mPaaS 10.1.68 upgrade guide or mPaaS 10.1.60 upgrade guide.

After you add the MSS SDK, you must configure the project before using the SDK.


The SDK version is 10.1.32 or later.

Note: You can view the current SDK version in the mpaas_sdk.config file.

 View the SDK version for iOS

Configure a project

Ensure that the meta.config file containing the MSS address and port number has been added to the project.

  • If you have used the latest plug-in to add the MSS SDK, the file will be generated automatically.

  • If your project does not contain the meta.config file, log in to the mPaaS console, choose Overview > Code configuration, download the .config file, rename it tometa.config, and add the file to your project.


Upgrade precautions

The Category file of the DTSyncInterface class does not need to be added since version 10.1.32. The middle tier implements package reading from meta.config. After an upgrade, check whether there is any configuration of the earlier version in the project. If yes, remove it. The following figure shows the Category file of the DTSyncInterface class to be removed from an upgraded version.

Configure a project

Code sample

To realize the logic for listening on the Sync service, you need to create a class, preferably a memory-resident service, to listen on Sync messages. The following code sample creates the MySyncService class to listen on the Sync service.

Before listening on the Sync service, you need define a Sync ID for the sync service (the sync ID will also be used when you create a push configuration on the mPaaS console). This sync ID is the link between you as the user and the service provider. The sync ID in the following example is SYNC-TRADE-DATA.

#import <MPMssAdapter/MPSyncInterface.h>

@implementation MySyncService
+ (instancetype)sharedInstance
    static MySyncService *bizService;

    static dispatch_once_t llSOnceToken;

    dispatch_once(&llSOnceToken, ^{

        bizService = [[self alloc] init];
    return bizService;

    self = [super init];
    if (self) {
        [MPSyncInterface initSync];
        BOOL registerSingleDeviceSync = [MPSyncInterface registerSyncBizWithName:SYNC_BIZ_NAME syncObserver:self selector:@selector(revSyncBizNotification:)];
        [MPSyncInterface bindUserWithSessionId:@"SESSION_DEMO"]; // In this function, **User** corresponds to userId that you specify in the console. It specifies the target to which the console delivers commands, and the value must be the same as that set in the userId function of MPaaSInterface. **SessionId** specifies the authorization token carried by the client. The user login system returns both userId and sessionId. If either changes, this function needs to be called again to ensure that a persistent connection is set up correctly.
    return self;

    NSDictionary *userInfo = notify.userInfo;
    dispatch_async(dispatch_get_main_queue(), ^{
        // Process business data.
        [MySyncService handleSyncData:userInfo];
        // Call back SyncSDK, indicating that business data has been 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"]; // Payload of the business data
                    NSData *dataPl = [[NSData alloc] initWithBase64EncodedString:plString options:kNilOptions];
                    NSString *pl = [[NSString alloc] initWithData:dataPl encoding:NSUTF8StringEncoding];
                    NSLog(@"biz payload data:%@,string:%@",dataPl,pl);
                     NSLog(@"biz payload:%@",plString);

    BOOL unRegisterSingleDeviceSync = [MPSyncInterface unRegisterSyncBizWithName:SYNC_BIZ_NAME syncObserver:[MySyncService sharedInstance]];
    [MPSyncInterface removeSyncNotificationObserver:self];

Follow-up steps