通过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;
        }
    }
}

你可能感兴趣的:(分享,share,AlertView,ActionShee)