集成友盟分享

首先添加友盟的sdk及設(shè)置分享跳轉(zhuǎn)的URL types,還有設(shè)置白名單

分享界面的設(shè)置,一般都是要求文字配圖片,圖片在上,文字在下,這個(gè)網(wǎng)上有好多的方法

我是自定義控件button

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

self.titleLabel.textAlignment = NSTextAlignmentCenter;

self.titleLabel.font = [UIFont systemFontOfSize:11.0];

[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[self setTitleColor:[UIColor colorWithRed:0.64f green:0.64f blue:0.64f alpha:1.00f] forState:UIControlStateHighlighted];

}

return self;

}

//取消按鈕的高亮狀態(tài)

- (void)setHighlighted:(BOOL)highlighted

{

}

-(void)layoutSubviews {

[super layoutSubviews];

// Center image

CGPoint center = self.imageView.center;

center.x = self.frame.size.width / 2;

center.y = self.imageView.frame.size.height / 2 + 15;

self.imageView.center = center;

self.imageView.size = CGSizeMake(50, 50);

//Center text

CGRect newFrame = [self titleLabel].frame;

newFrame.origin.x = 0;

newFrame.origin.y = self.imageView.frame.size.height + 20;

newFrame.size.width = self.frame.size.width;

self.titleLabel.frame = newFrame;

self.titleLabel.frame = CGRectMake(0, newFrame.origin.y, newFrame.size.width, 20);

self.titleLabel.textAlignment = NSTextAlignmentCenter;

}

然后是在視圖中設(shè)置布局,使用的是9宮格,要求的效果圖


.h

//點(diǎn)擊按鈕block回調(diào)

@property (nonatomic,copy) void(^btnClick)(NSInteger);

- (id)initWithShareHeadOprationWith:(NSArray *)titleArray andImageArry:(NSArray *)imageArr;

.m

- (id)initWithShareHeadOprationWith:(NSArray *)titleArray andImageArry:(NSArray *)imageArr

{

if (self = [super init]) {

self.shareBtnImgArray = imageArr;

self.shareBtnTitleArray = titleArray;

self.frame = CGRectMake(0, 0, SCREENW, SCREENH);

self.backgroundColor = ARGBColor(0.0, 0.0, 0.0, 0.3);

self.userInteractionEnabled = YES;

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedCancel)];

[self addGestureRecognizer:tapGesture];

[self loadUiConfig];

}

return self;

}

///? 加載9宮格的分享

- (void)loadUiConfig

{

[self addSubview:self.backGroundView];

[_backGroundView addSubview:self.cancelBtn];

for (NSInteger i = 0; i < _shareBtnImgArray.count; i++)

{

ActionButton *button = [ActionButton buttonWithType:UIButtonTypeCustom];

if (_shareBtnImgArray.count % 5 == 0) {

button.frame = CGRectMake(_backGroundView.bounds.size.width / 5 *(i % 5), (i / 5) * 100, _backGroundView.bounds.size.width / 5, 100);

}else{

button.frame = CGRectMake(_backGroundView.bounds.size.width / 5 * (i % 5), (i / 5) * 100, _backGroundView.bounds.size.width / 5, 100);

}

[button setTitle:_shareBtnTitleArray[i] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:_shareBtnImgArray[i]] forState:UIControlStateNormal];

button.tag = 200 + i;

[button addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];

[self.backGroundView addSubview:button];

}

if (_shareBtnImgArray.count > 5) {

UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 100, SCREENW, 1)];

lineView.backgroundColor = ARGBColor(215.0, 215.0, 215.0, 1.0);

[self.backGroundView addSubview:lineView];

}

[UIView animateWithDuration:0.25 animations:^{

_backGroundView.frame = CGRectMake(0, SCREENH - CGRectGetHeight(_backGroundView.frame), SCREENW, CGRectGetHeight(_backGroundView.frame));

}];

}

//

- (void)BtnClick:(UIButton *)btn

{

[self tappedCancel];

if (btn.tag < 200) {

_btnClick(btn.tag - 100);

}else{

_btnClick(btn.tag - 200);

}

}

- (void)tappedCancel

{

[UIView animateWithDuration:0.25 animations:^{

[self.backGroundView setFrame:CGRectMake(0, SCREENH, SCREENW, 0)];

self.alpha = 0;

} completion:^(BOOL finished) {

if (finished) {

[self removeFromSuperview];

}

}];

}

#pragma mark - 懶加載

- (UIView *)backGroundView

{

if (_backGroundView == nil) {

_backGroundView = [[UIView alloc] init];

_backGroundView.backgroundColor = ARGBColor(229.0, 229.0, 229.0, 1.0);

if (_shareBtnImgArray.count < 5) {

_backGroundView.frame = CGRectMake(0, SCREENH, SCREENW, 150);

}else{

NSInteger index;

if (_shareBtnTitleArray.count % 5 == 0) {

index =_shareBtnTitleArray.count / 5;

}else{

index = _shareBtnTitleArray.count / 5 + 1;

}

_backGroundView.frame = CGRectMake(0, SCREENH, SCREENW, 50 + 100 * index );

}

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(noTap)];

[_backGroundView addGestureRecognizer:tapGesture];

}

return _backGroundView;

}

- (void)noTap

{}

- (UIButton *)cancelBtn

{

if (_cancelBtn == nil) {

_cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];

_cancelBtn.frame = CGRectMake(0, CGRectGetHeight(_backGroundView.frame) - 50, CGRectGetWidth(_backGroundView.frame), 50);

[_cancelBtn setTitle:NSLocalizedString(@"button_cancel", nil) forState:UIControlStateNormal];

_cancelBtn.backgroundColor = [UIColor whiteColor];

[_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[_cancelBtn addTarget:self action:@selector(tappedCancel) forControlEvents:UIControlEventTouchUpInside];

}

return _cancelBtn;

}

分享是在工具類(lèi)中,避免appdelegate重代碼太多,有點(diǎn)小強(qiáng)迫

/**

*? 分享到各個(gè)平臺(tái)

*

*? @param PlatformName? 平臺(tái)名稱(chēng),在試圖控制器里配置,具體哪些平臺(tái)參考UMSocialSnsPlatformManager.h

*? @param text? ? ? ? ? 要分享的文本信息

*? @param description? ? 要分享的描述信息

*? @param image? ? ? ? ? 分享的圖片信息(可以傳NSData或UImage)

*? @param url? ? ? ? ? ? 要分享的網(wǎng)址

*? @param viewController 從哪個(gè)視圖控制器傳過(guò)來(lái)的(一般直接寫(xiě)self)

*/

+ (void)shareToSocialPlatform:(id)PlatformName WithTitle:(NSString *)text? andDescription:(NSString *)description andImage:(id)image andUrl:(NSString *)url showOn:(UIViewController *)viewController;

在.m中實(shí)現(xiàn)

+ (void)shareToSocialPlatform:(id)PlatformName WithTitle:(NSString *)text andDescription:(NSString *)description andImage:(id)image andUrl:(NSString *)url showOn:(UIViewController *)viewController

{

if ([PlatformName isEqualToString:UMShareToSina]) {

// __weak id weakSelf = viewController;

[[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"%@%@",text, url] shareImage:image socialUIDelegate:(id)viewController];

[UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(viewController,[UMSocialControllerService defaultControllerService],YES);

}else{

if ([PlatformName isEqualToString:UMShareToQQ]){

[UMSocialData defaultData].extConfig.qqData.url = url;

}else if ([PlatformName isEqualToString:UMShareToQzone]){

[UMSocialData defaultData].extConfig.qzoneData.url = url;

}else if ([PlatformName isEqualToString:UMShareToWechatSession]){

[UMSocialData defaultData].extConfig.wechatSessionData.url = url;

}else if ([PlatformName isEqualToString:UMShareToWechatTimeline]){

[UMSocialData defaultData].extConfig.wechatTimelineData.url = url;

}

[UMSocialData defaultData].extConfig.title = text;

[[UMSocialDataService defaultDataService] postSNSWithTypes:@[PlatformName] content:description image:image location:nil urlResource:nil presentedController:viewController completion:^(UMSocialResponseEntity* response) {

if (response.responseCode == UMSResponseCodeSuccess) {

}

}];

}

}

都具備了,直接在控制器中實(shí)現(xiàn)分享,由于項(xiàng)目需要實(shí)現(xiàn)語(yǔ)言國(guó)際化,所以titleArr使用的是語(yǔ)言包,有些鍵值不是分享的所以需要另外做判斷

shareArray = @[

@{@"titleArr":@[NSLocalizedString(@"menu_share_group", nil), NSLocalizedString(@"menu_share_friend", nil), NSLocalizedString(@"menu_share_weibo", nil), NSLocalizedString(@"menu_share_qq", nil), NSLocalizedString(@"menu_share_qzone", nil), NSLocalizedString(@"menu_copy_url", nil), NSLocalizedString(@"menu_add_reward", nil), NSLocalizedString(@"menu_add_comm", nil), NSLocalizedString(@"menu_ignore_meet", nil), NSLocalizedString(@"menu_delete_ask", nil)]},

@{@"imageArr":@[@"朋友圈.png", @"微信好友.png", @"微博.png", @"QQ.png", @"QQ空間.png", @"復(fù)制鏈接.png", @"追加懸賞.png", @"添加備注.png", @"省掉見(jiàn)面.png", @"刪除.png"]},

@{@"platformArr":@[UMShareToWechatTimeline,UMShareToWechatSession, UMShareToSina, UMShareToQQ,UMShareToQzone,@"lianJie",@"xuanShang",@"beiZhu",@"jianMian",@"shanChu"]}

];

}

shareArray = [CJUMengShare registerInstalled:shareArray];

ActionSheetView *shareView = [[ActionSheetView alloc]initWithShareHeadOprationWith:shareArray[0][@"titleArr"] andImageArry:shareArray[1][@"imageArr"]];

__weak id weakSelf = self;

[shareView setBtnClick:^(NSInteger btnTag) {

[weakSelf shareWithTitle:btnTag];

}];

[self.view addSubview:shareView];

// ?下面的方法是根據(jù)tag值來(lái)做相應(yīng)的事情,因?yàn)橐晥D中除了有分享還有別的功能邏輯,所以在下面判斷另行處理了

- (void)shareWithTitle:(NSInteger)btnTag

{

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言 友盟能實(shí)現(xiàn)分享功能,友盟+申請(qǐng)第三方賬號(hào)的目的: 進(jìn)行分享、授權(quán)操作需要在第三方平臺(tái)創(chuàng)建應(yīng)用并提交審核,友盟...
    CoderZb閱讀 9,916評(píng)論 8 60
  • 需要添加白名單:在info.list中的LSApplicationQueriesSchemes中添加 當(dāng)你的應(yīng)用在...
    FallPine閱讀 354評(píng)論 0 0
  • 1.通過(guò)Cocoapods集成 1.1配置平臺(tái)Cocoapods集成U-Share SDK可靈活配置平臺(tái),如工程t...
    Lost_693d閱讀 728評(píng)論 0 0
  • 因?yàn)槭切马?xiàng)目,所以我就索性重新集成最新6.1.0 版本的友盟. 然而6版本的友盟分享,是全新重構(gòu)的版本!所以有幾大...
    光彩影閱讀 16,752評(píng)論 29 13
  • 項(xiàng)目上線前,升級(jí)友盟分享的插件至新版本,發(fā)現(xiàn)android部分需要配置工程中各項(xiàng)內(nèi)容,意味著每次打新版都需要多一系...
    lyx2002py閱讀 1,899評(píng)論 0 0

友情鏈接更多精彩內(nèi)容