QQ相关集成
首先引入qq相关sdk
在appdelegate中写下面代码
#import "UMSocial.h"
#import "UMSocialQQHandler.h"
[UMSocialData setAppKey:@"55a5d6bb67e58ee22b002905"]; //appKey改成自己的
[UMSocialQQHandler setQQWithAppId:@"1105350688" appKey:@"rrs3kwdyl8AkqUtY" url:@"http://www.umeng.com/social"];
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL result = [UMSocialSnsService handleOpenURL:url];
if (result == FALSE) {
//调用其他SDK,例如支付宝SDK等
}
return result;
}
注:qq的url schemes是将qq平台的appid转换成16进制添加才可以跳转页面,否则提示没有安装qq
qq分享相关 QQ+appid十六进制
qq空间分享相关 tencent+appid
微信相关集成
在appdelegate中添加相关参数
[UMSocialWechatHandler setWXAppId:@"wxf408fb9ff8187119" appSecret:@"e2b271a60432dea49347b47b1222db4c" url:@"http://www.umeng.com/social"];
微信的appid
相关代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[UMSocialData setAppKey:@"55a5d6bb67e58ee22b002905"]; //appKey改成自己的
[UMSocialQQHandler setQQWithAppId:@"1105350688" appKey:@"rrs3kwdyl8AkqUtY" url:@"http://www.umeng.com/social"];
[UMSocialWechatHandler setWXAppId:@"wxf408fb9ff8187119" appSecret:@"e2b271a60432dea49347b47b1222db4c" url:@"http://www.umeng.com/social"];
return YES;
}
#import "ViewController.h"
@interface ViewController ()<UMSocialUIDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark 分享按钮
- (IBAction)shareClick:(UIButton *)sender {
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"55a5d6bb67e58ee22b002905"
shareText:@"友盟社会化分享让您快速实现分享等社会化功能,http://umeng.com/social"
shareImage:[UIImage imageNamed:@"icon"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToQzone,UMShareToQQ,UMShareToWechatSession,UMShareToWechatTimeline,nil]
delegate:self];
[UMSocialData defaultData].extConfig.qqData.url = @"http://baidu.com"; //qq分享点击跳转页面
[UMSocialData defaultData].extConfig.qzoneData.url = @"http://baidu.com"; //qq空间分享点击跳转页面
[UMSocialData defaultData].extConfig.qqData.title = @"QQ分享title"; //qq分享的标题
[UMSocialData defaultData].extConfig.qzoneData.title = @"Qzone分享title"; //qq空间分享标题
[UMSocialData defaultData].extConfig.qqData.qqMessageType = UMSocialQQMessageTypeDefault; //分享的文件类型
[UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://baidu.com"; //微信分享跳转页面
[UMSocialData defaultData].extConfig.wechatTimelineData.url = @"http://baidu.com"; //微信朋友圈跳转页面
[UMSocialData defaultData].extConfig.wechatSessionData.title = @"微信好友title"; //微信好友标题
[UMSocialData defaultData].extConfig.wechatTimelineData.title = @"微信朋友圈title"; //微信朋友圈分享标题
}
#pragma mark 显示sheet部分
- (BOOL)isDirectShareInIconActionSheet {
return YES;
}
#pragma mark 分享后返回数据
- (void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response {
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end