All Products
Search
Document Center

Mobile Platform as a Service:Use SDK

Last Updated:Feb 03, 2026

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.

Note

You can find the current SDK version in the mpaas_sdk.config file.

iOS查看SDK版本

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.config file does not exist in your project,

    Go to the Console > Code Management > Code Configuration page to download the .config configuration file. Then, rename the file to meta.config and add it to your project.

    meta_config

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