首页 > 代码库 > 友盟分享
友盟分享
—————————————集成—————————————
1. 导入框架包
2.Appdelegate.m 中做配置
1)#import "UMSocial.h" //友盟SDK
#import "UMSocialWechatHandler.h"//微信SDK
#import "UMSocialSinaHandler.h"//新浪微博SDK
2)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
}
}
if ([url.description hasPrefix:@"gocom"]) {
//你自己的逻辑
}
else {
return [UMSocialSnsService handleOpenURL:url];}
}
3)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//添加友盟
[UMSocialData setAppKey:IMShareMsgUMKey];
//设置微信AppId,设置分享url,默认使用友盟的网址
[UMSocialWechatHandler setWXAppId:IMShareWechatKey url:IMShareWechatUrl];
//打开新浪微博的SSO开关
[UMSocialSinaHandler openSSOWithRedirectURL:IMShareSinaUrl];
//添加友盟
[UMSocialData setAppKey:IMShareMsgUMKey];
//设置微信AppId,设置分享url,默认使用友盟的网址
[UMSocialWechatHandler setWXAppId:IMShareWechatKey url:IMShareWechatUrl];
//打开新浪微博的SSO开关
[UMSocialSinaHandler openSSOWithRedirectURL:IMShareSinaUrl];
4)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [UMSocialSnsService handleOpenURL:url];
}
* 打开分享到其他平台的列表
*
* @param sender 待分享的消息 (IMMsg)
*/
- (void)openShareList:(NSNotification *)sender
{
NSLog(@"正在打开分享列表");
IMMsg *msg = [sender object];
NSString *text = nil;
UIImage *image = nil;
//文本类型
if (msg.msgType == IMMsgTypeText)
{
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeText;
IMTextMsg * textMsg = (IMTextMsg *)msg;
text = textMsg.msgBody;
}
//图片类型
else if (msg.msgType == IMMsgTypePic)
{
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeImage;
IMPicMsg *picMsg = [sender object];
NSString *path = picMsg.originPicLocalPath;
image = [UIImage imageWithContentsOfFile:path];
}
[UMSocialSnsService presentSnsIconSheetView:self
appKey:IMShareMsgUMKey
shareText:text
shareImage:image
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToRenren,nil]
delegate:nil];
}
// [[UMSocialControllerService defaultControllerService] setShareText:@"底层接口分享测试" shareImage:nil socialUIDelegate:self];
// //设置分享内容和回调对象
// [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
// UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:@"http://www.baidu.com"];
// [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline] content:@"test test" image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
// if (response.responseCode == UMSResponseCodeSuccess) {
// NSLog(@"分享成功!");
// }
// }];
{
return [UMSocialSnsService handleOpenURL:url];
}
5)
—————————————方法实现—————————————
#pragma mark 图片 文本 分享
/**#pragma mark 图片 文本 分享
* 打开分享到其他平台的列表
*
* @param sender 待分享的消息 (IMMsg)
*/
- (void)openShareList:(NSNotification *)sender
{
NSLog(@"正在打开分享列表");
IMMsg *msg = [sender object];
NSString *text = nil;
UIImage *image = nil;
//文本类型
if (msg.msgType == IMMsgTypeText)
{
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeText;
IMTextMsg * textMsg = (IMTextMsg *)msg;
text = textMsg.msgBody;
}
//图片类型
else if (msg.msgType == IMMsgTypePic)
{
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeImage;
IMPicMsg *picMsg = [sender object];
NSString *path = picMsg.originPicLocalPath;
image = [UIImage imageWithContentsOfFile:path];
}
[UMSocialSnsService presentSnsIconSheetView:self
appKey:IMShareMsgUMKey
shareText:text
shareImage:image
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToRenren,nil]
delegate:nil];
}
// [[UMSocialControllerService defaultControllerService] setShareText:@"底层接口分享测试" shareImage:nil socialUIDelegate:self];
// //设置分享内容和回调对象
// [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
// UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:@"http://www.baidu.com"];
// [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline] content:@"test test" image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
// if (response.responseCode == UMSResponseCodeSuccess) {
// NSLog(@"分享成功!");
// }
// }];
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。