遇到的问题:当网址包含汉字时,可以分享成功,但只能显示一张大图,不能响应点击事件;
1\首先获取shareSDK的AppKey,进入后台创建应用,获取AppKey
2\cocoapods导入shareSDK
# 主模块(必须)
pod ‘ShareSDK3‘
# Mob 公共库(必须) 如果同时集成SMSSDK iOS2.0:可看此注意事项:http://bbs.mob.com/thread-20051-1-1.html
pod ‘MOBFoundation‘
# UI模块(非必须,需要用到ShareSDK提供的分享菜单栏和分享编辑页面需要以下1行)
pod ‘ShareSDK3/ShareSDKUI‘
# 平台SDK模块(对照一下平台,需要的加上。如果只需要QQ、微信、新浪微博,只需要以下3行)
pod ‘ShareSDK3/ShareSDKPlatforms/QQ‘
pod ‘ShareSDK3/ShareSDKPlatforms/SinaWeibo‘
pod ‘ShareSDK3/ShareSDKPlatforms/WeChat‘
pod ‘ShareSDK3/ShareSDKPlatforms/RenRen‘
pod ‘ShareSDK3/ShareSDKPlatforms/AliPaySocial‘
pod ‘ShareSDK3/ShareSDKPlatforms/Kakao‘
三、快速集成
第一步:设置ShareSDK的Appkey并初始化对应的第三方社交平台 打开*AppDelegate.m(*代表你的工程名字)导入头文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#import <ShareSDK/ShareSDK.h> #import <ShareSDKConnector/ShareSDKConnector.h> //腾讯开放平台(对应QQ和QQ空间)SDK头文件 #import <TencentOpenAPI/TencentOAuth.h> #import <TencentOpenAPI/QQApiInterface.h> //微信SDK头文件 #import "WXApi.h" //新浪微博SDK头文件 #import "WeiboSDK.h" //新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC" //人人SDK头文件 #import <RennSDK/RennSDK.h> |
在- (BOOL)application: didFinishLaunchingWithOptions:方法中调用registerApp方法来初始化SDK并且初始化第三方平台(各社交平台申请APPkey 的网址及申请流程汇总)
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /** * 设置ShareSDK的appKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login 登录后台进行应用注册, * 在将生成的AppKey传入到此方法中。 * 方法中的第二个第三个参数为需要连接社交平台SDK时触发, * 在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。 * 如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK。 */ [ShareSDK registerApp:@"iosv1101" activePlatforms:@[ @(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformTypeMail), @(SSDKPlatformTypeSMS), @(SSDKPlatformTypeCopy), @(SSDKPlatformTypeWechat), @(SSDKPlatformTypeQQ), @(SSDKPlatformTypeRenren), @(SSDKPlatformTypeGooglePlus)] onImport:^(SSDKPlatformType platformType) { switch (platformType) { case SSDKPlatformTypeWechat: [ShareSDKConnector connectWeChat:[WXApi class]]; break; case SSDKPlatformTypeQQ: [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]]; break; case SSDKPlatformTypeSinaWeibo: [ShareSDKConnector connectWeibo:[WeiboSDK class]]; break; case SSDKPlatformTypeRenren: [ShareSDKConnector connectRenren:[RennClient class]]; break; default: break; } } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) { switch (platformType) { case SSDKPlatformTypeSinaWeibo: //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权 [appInfo SSDKSetupSinaWeiboByAppKey:@"568898243" appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3" redirectUri:@"http://www.sharesdk.cn" authType:SSDKAuthTypeBoth]; break; case SSDKPlatformTypeWechat: [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885" appSecret:@"64020361b8ec4c99936c0e3999a9f249"]; break; case SSDKPlatformTypeQQ: [appInfo SSDKSetupQQByAppId:@"100371282" appKey:@"aed9b0303e3ed1e27bae87c33761161d" authType:SSDKAuthTypeBoth]; break; case SSDKPlatformTypeRenren: [appInfo SSDKSetupRenRenByAppId:@"226427" appKey:@"fc5b8aed373c4c27a05b712acba0f8c3" secretKey:@"f29df781abdd4f49beca5a2 z194676ca4" authType:SSDKAuthTypeBoth]; break; case SSDKPlatformTypeGooglePlus: [appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com" clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk" redirectUri:@"http://localhost" authType:SSDKAuthTypeBoth]; break; default: break; } }]; return YES; } (注意:每一个case对应一个break不要忘记填写,不然很可能有不必要的错误,新浪微博的外部库如果不要客户端分享或者不需要加关注微博的功能可以不添加,否则要添加,QQ,微信,google+这些外部库文件必须要加) |
第二步:添加实现代码 打开需要集成分享功能的视图
自己布置UI,在button点击事件中执行如下代码
UIImage *image = [UIImage imageNamed:@"60"];
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享内容"
images:image
url:[NSURL URLWithString:@"http://blog.sina.com.cn/s/blog_6b1e4a060102w9te.html"]
title:@"分享标题"
type:SSDKContentTypeAuto];
[ShareSDK share:SSDKPlatformSubTypeWechatTimeline parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
switch (state) {
case SSDKResponseStateSuccess:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
message:nil
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
break;
}
default:
break;
}
}];