如何向友盟分享面板添加自定义按钮,友盟文档已经有介绍,这里代码贴出来,供他人参考
1.在appdelegate里面,程序启动添加自定义的平台
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self customShare];
}
2.核心代码
- (void)customShare{
UMSocialSnsPlatform *snsPlatform = [[UMSocialSnsPlatform alloc] initWithPlatformName:@"CustomPlatform"];
// 设置自定义分享按钮的名称
snsPlatform.displayName = @"复制链接";
// 设置自定义分享按钮的图标
snsPlatform.bigImageName = @"copy";
__weak typeof(self) weakSelf = self;
// 监听自定义按钮的点击事件
snsPlatform.snsClickHandler = ^(UIViewController *presentingController, UMSocialControllerService * socialControllerService, BOOL isPresentInController){
UIPasteboard *pastboad = [UIPasteboard generalPasteboard];
pastboad.string = weakSelf.shareUrl;
UITabBarController *tab = (UITabBarController *)weakSelf.window.rootViewController;
UINavigationController *nav = tab.selectedViewController;
[nav showHint:@"复制链接成功"];
};
// 添加自定义平台
[UMSocialConfig addSocialSnsPlatform:@[snsPlatform]];
// 设置你要在分享面板中出现的平台
[UMSocialConfig setSnsPlatformNames:@[UMShareToWechatSession, UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone,UMShareToSms,@"CustomPlatform"]];
}
3.点击弹出分享面板
- (void)shareClick{
[UMSocialData defaultData].extConfig.wechatTimelineData.title = @"船长分享";
[UMSocialData defaultData].extConfig.wechatSessionData.title = @"船长分享";
[UMSocialData defaultData].extConfig.qqData.title = @"船长分享";
NSString *umurl=@"www.baidu.com";
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.shareUrl = umurl;
[UMSocialWechatHandler setWXAppId:@"wx74ed03bc22" appSecret:@"a3a" url:umurl];
[UMSocialQQHandler setQQWithAppId:@"999827" appKey:@"WFBhLc" url:umurl];
[UMSocialQQHandler setSupportWebView:YES];
NSString *shareText = [NSString stringWithFormat:@"chuanzhang"];
// 微信/朋友圈/QQ/QQ空间/短信/自定义复制按钮
NSArray *names = @[ UMShareToWechatSession, UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone,UMShareToSms,@"CustomPlatform"];
[UMSocialData defaultData].extConfig.smsData.snsName=@"【船长】";
[UMSocialData defaultData].extConfig.smsData.shareImage=nil;
[UMSocialSnsService presentSnsIconSheetView:self appKey:@"509" shareText:shareText shareImage:shareImage shareToSnsNames:names delegate:self];
}
4.分享按钮点击事件(针对短信平台)
-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData
{
// 短信分享处理
if (platformName == UMShareToSms) {
NSString *umurl=[NSString stringWithFormat:@"船长"];
socialData.shareText= [NSString stringWithFormat:@"船长"];
socialData.shareImage=nil;
//socialData.urlResource=[[UMSocialUrlResource alloc]initWithSnsResourceType:UMSocialUrlResourceTypeWeb url:umurl];
}
else{
// socialData.shareText = @"分享到其他平台的文字内容";
}
}