通过UIAlertView或者ActionSheet控件调用share方法

/*
 通过UIAlertView或者ActionSheet控件调用share方法时,如果在UIAlertView消失之前调用会出现崩溃,必须在UIAlertView消失以后调用。
 因为我们自己的UIAlertView或者ActionSheet没有释放掉,然后就调用share的ActionSheet
 */
- (IBAction)shareButton:(UIButton *)sender {

    //构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:@"这是编辑的文字这是编辑的文字这是编辑的文字"
                                       defaultContent:@"日鱼文化中心"
                                                image:[ShareSDK imageWithUrl:@"http://www.pinlehuo.com//d/file/activities/2015/05/554b13a8d8f96.jpg"]
                                                title:@"日鱼文化中心"
                                                  url:@"http://mobile.pinlehuo.com/index.php?g=Web&m=Free&type=4&free_id=89"
                                          description:@"日鱼文化中心"
                                            mediaType:SSPublishContentMediaTypeNews];


    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
    //弹出分享菜单
    [ShareSDK showShareActionSheet:container
                         shareList:nil
                           content:publishContent
                     statusBarTips:YES
                       authOptions:nil
                      shareOptions:nil
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {

                                if (state == SSResponseStateSuccess)
                                {
                                    NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));
                                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"分享成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                                    [alert show];


                                }
                                else if (state == SSResponseStateFail)
                                {
                                    NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
                                } 
                            }];




}


- (IBAction)alertButton:(id)sender {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"分享该活动,即可获得一次抽奖机会!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"分享", nil];
    alert.tag = 1314;
    [alert show];
}
//用这个方法会崩溃
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIButton *button = (UIButton *)[self.view viewWithTag:1];
    if (alertView.tag == 1314) {
        switch (buttonIndex) {
            case 0:
                NSLog(@"取消");
                break;
            case 1:
                [self shareButton:button];
                break;
            default:
                break;
        }
    }
}
//控件消失以后才能调用
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    UIButton *button = (UIButton *)[self.view viewWithTag:1];
    if (alertView.tag == 1314) {
        switch (buttonIndex) {
            case 0:
                NSLog(@"取消");
                break;
            case 1:
                [self shareButton:button];
                break;
            default:
                break;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值