supersdk

文档中心

文档中心

下载文档

MobShareSDK module


MobShareSDK provides sharing functions such as WeChat, Weibo, QQ, Facebook, and Twitter.

Precautions

Game developer needs to apply for the mob parameters and the parameters of the sharing platform that need to be integrated.

Engineering configuration

Download the MobShareSDK related files from the official website and import it into the project, then add the system dependency library.

 "libz.tbd",
 "libc++.tbd",
 "libsqlite3.tbd",

Sharing interface

Interface invoke:

// 个别平台分享参数安卓可能比iOS多,如追求与安卓相同可以多传,但是多传的参数iOS无效

 [SuperSDK invoke:@"mobsharesdk"
         funcName:@"mobShare"
       parameters:@{
                    @"title" : @"分享的标题", // 必传
                    @"content" : @"分享的内容", // 必传
                    @"url" : @"http://www.supersdk.cn", //URL字符串,可以包含中文,不可进行URL编码,没有可以不传
                    @"images" : [@"http://www.mob.com/images/logo_black.png"], //图片集合,传入参数可以为单张图片信息,也可以为一个NSArray,数组元素可以为UIImage、NSString(图片路径)、NSURL(图片路径)。如: @"http://www.mob.com/images/logo_black.png" 或 @[@"http://www.mob.com/images/logo_black.png"],没有可以不传
                    @"platform" : @"1" /*该字段选传,不传会拉起ShareSDK默认分享UI,
                    					 传了则不会拉起UI,直接调用对应平台分享接口:
                    					 新浪微博 1,
                    					 微信好友 2,
                    					 微信朋友圈 3,
                    					 微信收藏 4,
                    					 QQ好友 5,
                    					 QQ空间 6,
                    					 Facebook 7,
                    					 Instagram 8,
                    					 KakaoTalk 9,
                    					 KakaoStory 10,
                    					 Line 11,
                    					 Twitter 12,
                    					 VKontakte 13,
                   						*/
                    }];

Interface callback:

 - (void)handlerCallback:(NSString *)moduleName
               funcName:(NSString *)funcName
             parameters:(NSString *)parameters {
    NSLog(@"****** 收到回调\n moduleName : %@,\n funcName : %@,\n parameters : %@", moduleName, funcName, parameters);
    
    NSDictionary *retParam = nil;
    if (parameters) {
        NSData *jsonData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
        if (jsonData) {
            retParam = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
        }
    }
    
    int code = [[retParam objectForKey:@"code"] intValue];
    NSString *desc = [retParam objectForKey:@"msg"];
    id data  = [retParam objectForKey:@"data"];
    
    if ([moduleName isEqualToString:@"mobsharesdk"]) {// MobShareSDK模块回调
        
        if ([funcName isEqualToString:@"mobShare"]) {// 分享接口回调
            if(code == BCORE_SUCCESS) {
                NSLog(@"分享成功");
            }
            else {
                NSLog(@"分享失败");
            }
        }
    }
 }

Callback log printing:

收到回调
 moduleName : mobsharesdk,
 funcName : mobShare,
 result : {
  "msg" : "分享成功",
  "code" : 1
}

Special platform

KaKaoTalk sharing parameters need to be configured in the Kakao background. The parameters that need to be transmitted when invoking the mobShare interface are different neither.

NSDictionary *parameters = @{
                             @"platform" : @"9", // 必传,KaKaoTalk不能通过带ShareSDK默认UI的形式分享
                             @"url" : @"http://www.supersdk.cn", // 链接地址,为本地地址时默认分享文件形式,网络链接默认分享链接形式,没有可以不传
                             @"templateid" : @"11820", // 模板id,需要Kakao后台配置,必传
                             @"templateargs" : @{}, // 模板参数,没有可以不传
                             };
        
[SuperSDK invoke:@"mobsharesdk" funcName:@"mobShare" parameters:parameters];