关闭

友盟分享自定义

325人阅读 评论(0) 收藏 举报
分类:

自定义分享控制器,所有用到的分享界面都可以进行传递数据调用

建立分享的模型

//  NDShareModel.h


#import <Foundation/Foundation.h>


typedef NS_ENUM(NSInteger, ShareContentType){

    ShareContentTypeText,

    ShareContentTypeImage,

    ShareContentTypeApp,

    ShareContentTypeImageAndText

};


@interface NDShareModel : NSObject

@property(nonatomic,copy)NSString * shareTitle;

@property(nonatomic,copy)NSString * shareContent;

@property(nonatomic,copy)UIImage * shareImage;

@property(nonatomic,copy)NSString * shareUrl;

@property(nonatomic,assign)ShareContentType shareType;

@end


#import "NDShareModel.h"


@implementation NDShareModel


@end

分享的控制器

//

//  NDUmManger.h

//  Need

//

//  Created by 刘哓敏 on 15/11/8.

//  Copyright (c) 2015 weplanter. All rights reserved.

//


#import <Foundation/Foundation.h>

#import "NDShareModel.h"

typedef NS_ENUM(NSInteger, SharePlace)

{

    SharePlaceChaep,

    SharePlaceUserNorHome,

    SharePlaceUserKolHome,

    SharePlaceKolHome,

    SharePlaceTopicl,

    SharePlaceGoods,

    SharePlacePay,

    SharePlaceCoupe

};


@protocol NDShareUmMangerDelegate<NSObject>

@optional

-(void)selectedSharePlatform;

-(void)shareFinished;

@end

@interface NDShareUmManger : NSObject


@property(nonatomic,weak)id<NDShareUmMangerDelegate> shareDelegate;

@property(nonatomic,assign)SharePlace sharePlace;

+ (NDShareUmManger *) shareUmManage;

//系统分享

-(void)shareToUmWithWithController:(id)shareController andShareModel:(NDShareModel *)shareModel andShareSnsTypes:(NSArray *)typesArray;

//单分享

-(void)shareToUmWithWithController:(id)shareController andPlatform:(NSString *)platform andSahreModel:(NDShareModel *)shareModel;

//分享大图

@end

//

//  NDUmManger.m

//  Need

//

//  Created by 刘哓敏 on 15/11/8.

//  Copyright (c) 2015 weplanter. All rights reserved.

//


#import "NDShareUmManger.h"


#import "UMSocialDataService.h"

#import "UMSocial.h"

#import "WXApi.h"


@interface NDShareUmManger()

{

    NDShareModel * shareUmModel;

    UIViewController * shareUmController;

}

@end

@implementation NDShareUmManger


+(NDShareUmManger *)shareUmManage

{

    static NDShareUmManger * shareManger = nil;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        shareManger = [[self alloc]init];

    });

    return shareManger;

    

}

#pragma mark - 原生分享(文字加图片)

-(void)shareToUmWithWithController:(id)shareController andShareModel:(NDShareModel *)shareModel  andShareSnsTypes:(NSArray *)typesArray

{

    shareUmModel = shareModel;

    shareUmController = shareController;

    [UMSocialSnsService presentSnsIconSheetView:shareController appKey:UMeng_APIKey shareText:nil  shareImage:nil shareToSnsNames:typesArray delegate:(id)self];

}

#pragma mark - 自定义分享到某一开放平台(文字加图片)

-(void)shareToUmWithWithController:(id)shareController andPlatform:(NSString *)platform andSahreModel:(NDShareModel *)shareModel

{

    if([WXApi isWXAppInstalled])

    {

        shareUmModel = shareModel;

        shareUmController = shareController;

        [[UMSocialControllerService defaultControllerService] setShareText:nil shareImage:nil  socialUIDelegate:(id)self];        //设置分享内容和回调对象

        [UMSocialSnsPlatformManager getSocialPlatformWithName:platform].snsClickHandler((id)self,[UMSocialControllerService defaultControllerService],YES);

    }else

    {

        [self alterViewWithStr:@"您还未安装微信"];

    }

}

#pragma mark - um Delegate

//下面可以设置根据点击不同的分享平台,设置不同的分享文字

-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData

{

    [self.shareDelegate selectedSharePlatform];

    [UMSocialConfig setFinishToastIsHidden:YES  position:UMSocialiToastPositionCenter];

    

    socialData.extConfig.wechatSessionData.url = shareUmModel.shareUrl;  //微信好友

    socialData.extConfig.wechatTimelineData.url = shareUmModel.shareUrl; //朋友圈

    socialData.extConfig.qqData.url = shareUmModel.shareUrl;             //QQ好友

    socialData.extConfig.qzoneData.url = shareUmModel.shareUrl;           //QQ空间

    //分享图片

    socialData.shareImage = shareUmModel.shareImage;


    if ([platformName isEqualToString:UMShareToWechatTimeline]||[platformName isEqualToString:UMShareToQzone]) {  //朋友圈 qq空间

        socialData.extConfig.title = shareUmModel.shareTitle;


    }else if([platformName isEqualToString:UMShareToSina])

    {

        socialData.shareText = [NSString stringWithFormat:@"%@, %@, %@",shareUmModel.shareTitle,shareUmModel.shareContent,shareUmModel.shareUrl];

    }else

    {

        //标题,用于指定微信分享标题,qzone分享的标题和邮件分享的标题。

        socialData.extConfig.title =shareUmModel.shareTitle;

        socialData.shareText = shareUmModel.shareContent;

    }

}

//下面得到分享完成的回调

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response

{

    NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);

    if(response.responseCode == UMSResponseCodeSuccess)

    {

       [self.shareDelegate shareFinished];

       [self alterViewWithStr:@"分享成功"];

    }

}

-(void)alterViewWithStr:(NSString *)str

{

    UILabel * alterLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-55, ScreenHeight/2-15, 110, 30)];

    alterLabel.textAlignment = NSTextAlignmentCenter;

    [shareUmController.view addSubview:alterLabel];

    alterLabel.text = str;

    alterLabel.layer.cornerRadius = 10;

    alterLabel.alpha = 0.7;

    alterLabel.clipsToBounds = YES;

    alterLabel.font = [UIFont systemFontOfSize:14.0f];

    alterLabel.backgroundColor = [UIColor blackColor];

    alterLabel.textColor = [UIColor whiteColor];

    [UIView animateWithDuration:2.5f animations:^{

        

        alterLabel.alpha = 0.0f;

        

    }];

}

@end




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:26512次
    • 积分:933
    • 等级:
    • 排名:千里之外
    • 原创:62篇
    • 转载:53篇
    • 译文:0篇
    • 评论:0条