第三方友盟分享大全

- (void)createShareView
{
    
   
    waitingview = [[UIControl alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [waitingview addTarget:self action:@selector(shareCancel) forControlEvents:UIControlEventTouchUpInside];
    waitingview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    waitingview.alpha = 0;
    [[UIApplication sharedApplication].keyWindow addSubview:waitingview];
    
    bgView = [ZZControll createViewWithFrame:CGRectMake1(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100*ScaleX) color:[UIColor whiteColor]];
    
    [waitingview addSubview:bgView];
    
    NSArray *titleArray = @[@"朋友圈",@"微信好友",@"QQ空间",@"QQ好友"];
    NSArray *imageArray = @[@"xi_fen_peng.png",@"xi_fen_wei.png",@"xi_fen_kong.png",@"xi_fen_qq.png",@""];
    for (int i = 0; i<4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(10*ScaleX+i%4*(320/4)*ScaleX, 10+i/4*75, 50*ScaleX, 50*ScaleX);
        [btn setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
        btn.tag = 100+i;
        btn.layer.cornerRadius = 25*ScaleX;
        btn.layer.masksToBounds = YES;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
        
        UILabel *label = [ZZControll createLabelWithFrame:CGRectMake(btn.frame.origin.x, btn.frame.size.height+btn.frame.origin.y, 50*ScaleX, 15*ScaleX) Font:10*ScaleX Text:titleArray[i]];
        label.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:label];
    }
    
    UIView *view = [ZZControll createViewWithFrame:CGRectMake(0, 160*ScaleX, SCREEN_WIDTH, 1) color:[UIColor grayColor]];
    [bgView addSubview:view];
    
    UIButton *cancelBtn = [ZZControll createButtonWithFrame:CGRectMake(0, 161*ScaleX, SCREEN_WIDTH, 39*ScaleX) ImageName:nil Target:self Action:@selector(shareCancel) Title:nil];
    [cancelBtn setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
    [bgView addSubview:cancelBtn];
    
    [UIView animateWithDuration:0.3 animations:^{
        waitingview.alpha=1;
        bgView.frame = CGRectMake(0, SCREEN_HEIGHT-100*ScaleX, SCREEN_WIDTH, 100*ScaleX);
    }];
}

- (void)shareCancel
{
    [UIView animateWithDuration:0.2 animations:^{
        
        bgView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100*ScaleX);
        waitingview.alpha=0;
    }completion:^(BOOL finished) {
        [waitingview removeFromSuperview];
    }];
}

- (void)btnClick:(UIButton *)btn
{
    //由于苹果审核政策需求,建议大家对未安装客户端平台进行隐藏,在设置QQ、微信AppID之后调用下面的方法,
   // [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatTimeline]];
    
    
    [self shareCancel];
    
    NSString *shareText = self.title1;
    UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:self.imageUrl];//分享的图片
     NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
   //此处解决分享QQ空间显示手机打不开QQ问题就是将URL转化成NSUTF8StringEncoding
    self.showUrl = [[userDefaultes objectForKey:InviteUrl] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    self.showUrl = [model.inviteUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //  self.url = [NSString stringWithFormat:@"%@",url];
    
    switch (btn.tag) {
        case 100:
            NSLog(@"朋友圈");
        {
            
            [UMSocialData defaultData].extConfig.wechatTimelineData.title = self.title2;
            [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.showUrl;
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:shareText image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功!");
                    
                }
            }];
        }
            
            
            break;
        case 101:
            NSLog(@"微信好友");
        {
            
            [UMSocialData defaultData].extConfig.wechatSessionData.title = self.title2;
            [UMSocialData defaultData].extConfig.wechatSessionData.url = self.showUrl;
            
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:shareText image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功!");
                }
            }];
        }
            
            break;
        
        case 102:
            NSLog(@"QQ空间");
        {
            [UMSocialData defaultData].extConfig.qzoneData.title = self.title2;
            [UMSocialData defaultData].extConfig.qzoneData.url = self.showUrl;
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:shareText image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功!");
                }
            }];
        }
            
            break;
        case 103:
            NSLog(@"QQ好友");
        {
            [UMSocialData defaultData].extConfig.qqData.title = self.title2;


QQ好友分享问题,将获得的URL进行截取解决了这个问题

            NSString *str = [self.showUrl substringToIndex:[self.showUrl length]- 6];

            [UMSocialData defaultData].extConfig.qqData.url = str;
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:shareText image:nil location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功!");
                }
            }];
        }
            
            break;
                    
        default:
            break;
    }
    
}


-(void)didCloseUIViewController:(UMSViewControllerType)fromViewControllerType
{
    NSLog(@"didClose is %d",fromViewControllerType);
}

//下面得到分享完成的回调
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}

-(void)didFinishShareInShakeView:(UMSocialResponseEntity *)response
{
    NSLog(@"finish share with response is %@",response);
}

-(BOOL)isDirectShareInIconActionSheet
{
    return YES;
}


- (void)navigationLeftButtonClick:(id)sender
{
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (tempAppDelegate.LeftSlideVC.closed) {
        
        [tempAppDelegate.LeftSlideVC openLeftView];
    }
    else{
        [tempAppDelegate.LeftSlideVC closeLeftView];
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值