一、ShareSDK新增功能
——应用信息配置文件,分享内容配置文件使用说明
概览:为了开发者更方便的使用ShareSDK并实现分享功能,在使用ShareSDK的时候可以直接配置名为ShareSDK.xml 以及 ShareContent.xml 的XML格式文件,实现快速分享,有效减少代码的数量,并实现”一句代码即可分享”功能。(两个文件可以单独使用,没有互相依赖关系;但是对于希望节省代码并快速简单实现分享的用户来说,建议两个文件同时使用)
【具体用例请参考 Demo 中的 IntergratingShareSDKWithConfigurationFile 示例项目】
二、ShareSDK.xml
用于配置各平台的应用配置信息。可以在ShareSDK.xml填写各个平台的配置信息例如appkey,appid等。ShareSDK.xml文件位于Optional文件中的ShareSDKConfigFile.bundle资源文件中。使用的时候请解开注释,并填入您自己的应用配置信息(请勿改动任何参数名称,仅修改您需要传入的应用配置信息即可)。填写完毕好请保存好,即可免去ShareSDK原来的初始化方法,自动进行各个平台的初始化。(注:对于需要使用原生SDK的平台,仍需要写连接器的链接方法)
该文件的配置格式请参考Demo所提供的ShareSDK.xml文件
ShareSDK.xml示例
二、ShareContent.xml
用于配置分享内容。文件同样存放于Optional文件中的ShareSDKConfigFile.bundle资源文件中。该文件搭配ShareSDK中新增的接口使用
1
2
3
4
5
6
7
+ (void)shareWithContentName:(NSString *)contentName
platform:(SSDKPlatformType)platformType
customFields:(NSDictionary *)customFields
onStateChanged:(SSDKShareStateChangedHandler)stateChangedHandler;
用法说明:
1.先配置好ShareContent.xml文件:
i.文件中的节点包含有 “name”的属性,需要自行填写一个任意字符串标识。也可以创建多个节点,并对name传入不同标识来区别不同的Content。
在使用上述新增接口时,实际分享的内容会依照 首个参数 contentName 来寻找不同的节点并获取其中的内容。
ii. 在节点中至少应填写节点中的各参数,以作为最基本的分享内容。而其他以平台名称命名的节点(如),则是用于定制各特定平台的分享内容所用到。
iii.(可选)上述接口中第三个参数customContent可用于自定义的替换xml文件中指定字符。
示例:
customContent是一个字典,可以自由定制key和value。key应为在中存在的 字符串,而value则为替换的字符串。
如这是你的customContent字典
1
2
3
4
5
6
7
8
9
10
11
customContent =
{
filedA : “这是替换上去的字符串”,
filedB : “这也是!”,
sinaFieldA: “这个是新浪定制”
}
这是你的xml文件中的Content节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
my text is {fieldA}
my title is {fieldB}http://mob.com
some.jpg
my sina text is {sinaFieldA}
my sina title那么最终分享出去的基本参数的text实际内容为”my text is 这是替换上去的字符串”,title实际内容为”my title is 这也是!”;
而定制了新浪的text实际内容为”my sina text is 这个是新浪定制”
如此类推。所有的key值都会被搜索并替换。这样的话开发者就能够自由地以类似参数的形式来控制分享的内容了。开发者可以通过动态控制传入的NSDictionary,来实现动态的改变分享的内容。
iv(可选):
在XML文件中,支持节点之间的继承关系。如父节点为:
1
2
3
4
5
….
如需要增加子节点继承父节点,可以新增一属性parent。例如:
1
2
3
4
5
….
实际分享时,子节点会继承父节点内容,子节点不具有的参数,而父节点具有,则会被补充到子节点上。
ShareContent.xml示例:
2.准备好ShareContent.xml文件之后,就可以调用上述新增接口进行分享了!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#import
[ShareSDK shareWithContentName:@"mob" /*对应的节点的name 属性*/
platform:self.platformType /*目标分享平台类型*/
customFields:specialFied /*自定义替换字符的字典,也可以传空*/
onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error)
{
switch (state)
{
//根据分享结果的状态码处理您的业务代码
//…
}
}];
3.使用xml文件配置信息,在3.4.2版本中我们添加了调用我们UI的分享接口
(1)使用我们的分享菜单以及编辑界面的接口:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import
NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"jpg"];
NSDictionary *customContent = @{@"text":@"Lisa",
@"title":@"标题",
@"imgUrl":imgPath};
[ShareSDK showShareActionSheet:view items:nil contentName:@"ShareSDK" customFields:customContent onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
message:[NSString stringWithFormat:@"%@", error]
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
default:
break;
}
}];
(2)不要我们的分享菜单,只要编辑界面的接口:
Objective-C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import
NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"jpg"];
NSDictionary *customContent = @{@"text":@"Lisa",
@"title":@"标题",
@"imgUrl":imgPath};
[ShareSDK showShareEditor:SSDKPlatformTypeSinaWeibo otherPlatformTypes:nil contentName:@"ShareSDK" customFields:customContent onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
message:[NSString stringWithFormat:@"%@", error]
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
default:
break;
}
}];