All Products
Search
Document Center

Mobile Platform as a Service:Use SDK

Last Updated:Dec 04, 2023

After you add the SDK for the Social sharing component, you need to configure the project. You can start to use this component after it has been initialized. This topic describes how to use the Social sharing SDK of the baseline version 10.1.60 and later based on the Official demo

Configure the project

Configure the allowlist of third-party applications

In iOS 9 and later, configure the Scheme list to support application operations such as social sharing and authorization. The system will automatically check whether the Scheme of the application is set in theinfo.plist file of the project. If the Scheme of the target application is not configured, the current application will be unable to jump to the target application.

p3.png

The Value corresponding to each channel is as follows:

  • Wechat: weixinULAPI, wechat, weixin.

  • weibo: sinaweibohd, sinaweibo, weibosdk, weibosdk2.5.

  • Alipay: alipay, alipayShare.

  • QQ: mqq, mqqapi, mqqwpa, mqqOpensdkSSoLogin.

  • Ding Talk: dingtalk, dingtalk-open.

Configure URL Scheme

To ensure that you can jump back to the current application from other channel applications, you need to add the urlScheme value in the Info.plist file of the current project. The value is obtained from the corresponding social sharing channel. 

  • The scheme for WeChat is the assigned key.

  • The scheme for Weibo is "wb" + key.

  • The scheme for QQ is "tencent" + APPID.

  • The Identifier for Alipay is alipayShare, and the scheme for it is 'ap' + APPID.

Initialization

When using the Social sharing component, you first need to create the application information in the corresponding third-party platform, then use this information for registration. The information includes appId, appSecret, and universalLink. The methods used for registration are as follows. 

When using mPaaS framework

Implement the following method in the classification of DTFrameworkInterface, and return the values of key and secret in the form of a dictionary in this method. 

Note

In version 10.1.60 and later of the mPaaS SDK, the WeChat SDK has been updated to version 1.8.6.1, which required Universal Link verification. Therefore, you need to configure the corresponding Universal Link at the same time when configuring the key. 

- (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *configDic = @{
        @"weixin" : @{@"key":@"xxxxxxxxxxxxxx", @"secret":@"xxxxxxxxxxxxxxx", @"universalLink":@"https://mpaas.example.com/"},
        @"weibo" : @{@"key":@"xxxxxxxxxx", @"secret":@"xxxxxxxxxxxxxxxxx"},
        @"qq" : @{@"key":@"xxxxxxxxx", @"secret":@"xxxxxxxxxx"},
        @"alipay": @{@"key":@"xxxxxxxxxxxxx"},/*The bundleID corresponding to this key is "com.alipay.share.demo". If you need to use it for testing, please modify it to the key you applied for or modify the bundleID to "com.alipay.share.demo"*/
        @"dingTalk": @{@"key":@"xxxxxxxxxxxxxxxx"}};
    [APSKClient registerAPPConfig:configDic];
}

When not using mPaaS framework

Register the key in the initialization method of the accessed application. 

Note

In version 10.1.60 and later of the mPaaS SDK, the WeChat SDK has been updated to version 1.8.6.1, which requires Universal Link verification. Therefore, you need to configure the corresponding Universal Link at the same time when configuring the key. 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *dic = @{
        @"weixin" : @{@"key":@"xxxxxxxxxxxxxx", @"secret":@"xxxxxxxxxxxxxxx",@"universalLink":@"https://mpaas.example.com/"},
        @"weibo" : @{@"key":@"xxxxxxxxxx", @"secret":@"xxxxxxxxxxxxxxx"},
        @"qq" : @{@"key":@"xxxxxxxxxx", @"secret":@"xxxxxxxxxxxxxx"},
        @"alipay" : @{@"key":@"xxxxxxxxxxxxxxxx"},/*The bundleID corresponding to this key is "com.alipay.share.demo". If you need to use it for testing, please modify it to the key you applied for or modify the bundleID to "com.alipay.share.demo"*/
        @"dingTalk": @{@"key":@"xxxxxxxxxxxxxxxxxxx"}};
    [APSKClient registerAPPConfig:dic];
}

Basic functions

Social sharing

Trigger the Social sharing panel

You can specify the channel to be displayed while triggering the Social sharing panel. 

NSArray *channelArr = @[kAPSKChannelQQ, kAPSKChannelLaiwangContacts, kAPSKChannelLaiwangTimeline, kAPSKChannelWeibo, kAPSKChannelWeixin, kAPSKChannelCopyLink,kAPSKChannelDingTalkSession];

self.launchPad = [[APSKLaunchpad alloc] initWithChannels:channelArr sort:NO];
self.launchPad.delegate = self;  
[self.launchPad showForView:[[UIApplication sharedApplication] keyWindow] animated:YES];

Complete social sharing

Execute the social sharing operation in the callback of the sharingLaunchpad method in @protocol APSKLaunchpadDelegate

- (void)sharingLaunchpad:(APSKLaunchpad *)launchpad didSelectChannel:(NSString *)channelName
{
    [self shareUrl:channelName];
    [self.launchPad dismissAnimated:YES];
}

- (void)shareUrl:(NSString*)channelName
{
    // Generate data and call the corresponding channel for social sharing.
    APSKMessage *message = [[APSKMessage alloc] init];
    message.contentType = @"url";//The types are "text", "image", and "url".
    message.content = [NSURL URLWithString:@"www.example.com.cn"];
    message.icon = [UIImage imageNamed:@"1"];
    message.title = @"Title";
    message.desc = @"Description";

    APSKClient *client = [[APSKClient alloc] init];

    [client shareMessage:message toChannel:channelName completionBlock:^(NSError *error, NSDictionary *userInfo) {
        // userInfo is the extension information.
        if(!error)
        {
            //your logistic
        }
        NSLog(@"error = %@", error);
    }];    
}

Jump back from the channel application

  • When using the mPaaS framework, you do not need to manually handle it. 

  • When not using the mPaaS framework, refer to the following code snippet. 

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    // After the social sharing is complete, return from the channel application to the source application.
    BOOL ret;  
    ret = [APSKClient handleOpenURL:url];  
    return ret;
}

Open service

Through open interfaces of third-party services, you can call other open services provided by the Social sharing SDK of the third-party channel. The open services that are currently supported are One-time subscription information and Launch Mini Program services provided by WeChat.

Operating procedure for requesting open services

The following code snippet shows the operating procedure for requesting open services:

// 1. Create the request object.
APSKOpenServiceRequest *req = [APSKOpenServiceRequest new];
// 2. Set the request type.
req.requestType = APSKOpenServiceRequestTypeLaunchMini;
// 3. Set the required parameters.
MPSKLaunchMiniProgramParam *param = [[MPSKLaunchMiniProgramParam alloc] init];
param.userName = @"xxxxxxxx";
param.path = @"/index.html";
param.miniProgramType = MPSKWXMiniProgramTypeTest;

req.param = param;

// 4. Create the client object
APSKClient *client = [APSKClient new];
// 5. Request service
[client requestOpenService:req toChannel:kAPSKChannelWeixin completionBlock:^(NSError *error, NSDictionary *userInfo) {
    // 6. Callback.
    if (error) {
        NSLog(@"%@", error);
    }
}];

Jump back from the channel application

After you jump back from the channel application, the handling depends on whether the mPaaS framework is used on the client. 

  • If the mPaaS framework is used on the client, the framework will handle it after the jump back. 

  • If the mPaaS framework is not used on the client, refer to the following code snippet to handle it after the jump back. 

  - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  {
      // Return from the channel application to the source application.
      BOOL ret;  
      ret = [APSKClient handleOpenURL:url];  
      return ret;
  }