After adding the Share component SDK, configure your project. The Share component can be used after it is initialized.
This topic uses the official Share Demo to demonstrate how to use the Share SDK for baselines 10.1.60 and later.
Configure the project
Configure the whitelist for third-party application redirects
In iOS 9 and later, you must configure a Scheme list to support application sharing and authorization. The system automatically checks the info.plist file for the application's scheme. An application cannot redirect if its scheme is not configured.

The `Value` for each channel is as follows:
WeChat: weixinULAPI, wechat, weixin.
Weibo: sinaweibohd, sinaweibo, weibosdk, weibosdk2.5.
Alipay: alipay, alipayShare.
QQ: mqq, mqqapi, mqqwpa, mqqOpensdkSSoLogin.
DingTalk: dingtalk, dingtalk-open.
Configure the URL Scheme
To ensure correct redirection from a third-party application back to your application, add a `urlScheme` to your project's `Info.plist` file. You can obtain the `urlScheme` from each sharing channel.
The callback 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 is
'ap' + APPID.
Initialization
To use the Share component, you must first create your application on the third-party platform. Then, register your application with its information, such as `appId`, `appSecret`, and `universalLink`. The following sections describe the registration methods.
When using the mPaaS framework
Implement the following method in the `DTFrameworkInterface` category. In this method, return the `key` and `secret` values as a dictionary.
As of mPaaS SDK v10.1.60, the WeChat SDK has been updated to v1.8.6.1 and requires Universal Link verification. Therefore, you must configure the corresponding Universal Link when you configure 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". For testing, change it to your own requested key or change the bundleID to "com.alipay.share.demo".*/
@"dingTalk": @{@"key":@"xxxxxxxxxxxxxxxx"}};
[APSKClient registerAPPConfig:configDic];
}When not using the mPaaS framework
Register the key in the application's startup method.
As of mPaaS SDK v10.1.60, the WeChat SDK has been updated to v1.8.6.1 and requires Universal Link verification. Therefore, you must configure the corresponding Universal Link when you configure 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". For testing, change it to your own requested key or change the bundleID to "com.alipay.share.demo".*/
@"dingTalk": @{@"key":@"xxxxxxxxxxxxxxxxxxx"}};
[APSKClient registerAPPConfig:dic];
}Basic features
Sharing
Open the sharing panel
When you open the sharing panel, you can specify the channels to display.
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 the sharing operation
You can perform the sharing operation in the sharingLaunchpad callback of @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 to share.
APSKMessage *message = [[APSKMessage alloc] init];
message.contentType = @"url"; // The content type can be "text", "image", or "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 for extended information.
if(!error)
{
// Your logic
}
NSLog(@"error = %@", error);
}];
}Handle redirection from the channel application
If you use the mPaaS framework, no action is required. The framework handles the redirection.
If you do not use the mPaaS framework, handle the redirection using the following code.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Handle the redirection from the channel app back to the source app after a successful share.
BOOL ret;
ret = [APSKClient handleOpenURL:url];
return ret;
}Open services
You can use the third-party developer service interface to call other open services provided by the third-party channel's Share SDK. Currently, the supported open services are WeChat one-time subscription messages and launching WeChat mini programs.
Procedure to request open services
The procedure to request open services is as follows:
// 1. Create a 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 a client object.
APSKClient *client = [APSKClient new];
// 5. Request the service.
[client requestOpenService:req toChannel:kAPSKChannelWeixin completionBlock:^(NSError *error, NSDictionary *userInfo) {
// 6. Callback.
if (error) {
NSLog(@"%@", error);
}
}];Handle redirection from the channel application
After returning from the third-party application, refer to the following code to handle the callback.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// Handle the redirection from the channel app back to the source app.
BOOL ret;
ret = [APSKClient handleOpenURL:url];
return ret;
}