天天看點

通過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 = ;
    [alert show];
}
//用這個方法會崩潰
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIButton *button = (UIButton *)[self.view viewWithTag:];
    if (alertView.tag == ) {
        switch (buttonIndex) {
            case :
                NSLog(@"取消");
                break;
            case :
                [self shareButton:button];
                break;
            default:
                break;
        }
    }
}
//控件消失以後才能調用
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    UIButton *button = (UIButton *)[self.view viewWithTag:];
    if (alertView.tag == ) {
        switch (buttonIndex) {
            case :
                NSLog(@"取消");
                break;
            case :
                [self shareButton:button];
                break;
            default:
                break;
        }
    }
}
           

繼續閱讀