码迷,mamicode.com
首页 > 其他好文 > 详细

实现友盟分享

时间:2014-07-29 17:01:12      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   os   io   for   cti   ar   

-(void)shareWork:(id)sender{

    UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"关闭" destructiveButtonTitle:nil otherButtonTitles:@"分享到新浪微博", @"分享给微信好友", @"分享到朋友圈",@"用短信分享", nil];

    share.actionSheetStyle = UIActionSheetStyleBlackOpaque;

    [share showInView:self.view];

}

//分享的代理

#pragma mark ------UIActionSheetDelegate---------

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if(actionSheet.cancelButtonIndex == buttonIndex){

        [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];

        return ;

    }

    

    NSString *urlStr = [NSString stringWithFormat:@"http://styler.shishangmao.cn/work/%@", @(self.work.id)];

    NSString *title;

    NSArray *platformTypes;

    switch (buttonIndex) {

            

        case 0://分享到新浪微博

            title = [NSString stringWithFormat:@"%@的作品%@ @时尚猫官方微博 %@",self.work.stylist.nickName, self.work.title, urlStr];

            platformTypes = @[UMShareToSina];

            [MobClick event:log_event_name_share_to_sina_weibo attributes:[NSDictionary dictionaryWithObjectsAndKeys:@(self.work.id), @"作品id", nil]];

            break;

        case 1://分享给微信好友

            title = [NSString stringWithFormat:@"%@",self.work.title];

            platformTypes = @[UMShareToWechatSession];

            [UMSocialData defaultData].extConfig.title = title;

            [UMSocialData defaultData].extConfig.wechatSessionData.url = urlStr;

            

            [MobClick event:log_event_name_share_to_wechat_session attributes:[NSDictionary dictionaryWithObjectsAndKeys:@(self.work.id), @"机构id", nil]];

            break;

        case 2://友分享到朋友圈

            [[UMSocialControllerService defaultControllerService] setShareText:self.work.title shareImage:self.shareImage socialUIDelegate:self];

            [UMSocialData defaultData].extConfig.wechatTimelineData.url = urlStr;

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

            

            [MobClick event:log_event_name_share_to_wechat attributes:[NSDictionary dictionaryWithObjectsAndKeys:@(self.work.id), @"机构id", nil]];

            break;

        case 3://用短信分享

            title = [NSString stringWithFormat:@"%@ %@", self.work.title,urlStr];

            platformTypes = @[UMShareToSms];

            

            [MobClick event:log_event_name_share_to_sms attributes:[NSDictionary dictionaryWithObjectsAndKeys:@(self.work.id), @"机构id", nil]];

            break;

        default:

            break;

    }

    if (buttonIndex <= 3) {

        [[UMSocialDataService defaultDataService] postSNSWithTypes:platformTypes content:title image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){

            if (response.responseCode == UMSResponseCodeSuccess) {

                [SVProgressHUD showSuccessWithStatus:@"分享成功" duration:0.5];

                NSString *urlString = [NSString stringWithFormat:@"/works/%d/lastShareTime",self.work.id];

                [[StylistWorkStore sharedStore] shareStylistWork:^(NSError *err) {

                    NSLog(@"========%@",err);

                } url:urlString];

                

                

//  //分享用put方式更新时间

//                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[AppStatus sharedInstance].apiUrl,urlString]]

//                                                                       cachePolicy:NSURLCacheStorageNotAllowed

//                                                                   timeoutInterval:60.0];

//                [request setValue:[[AppStatus sharedInstance] ua] forHTTPHeaderField:@"User-Agent"];

//                [request setHTTPMethod:@"PUT"];

//                NSURLResponse *response = nil;

//

//                NSError *error = nil;

//                NSData* downloadedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

//                if (error){

//                    NSLog(@">>%@", [error description]);

//                }

//                

//                NSLog(@"======%@ ",downloadedData);

                

                

            }

        }];

    }

}

实现友盟分享,布布扣,bubuko.com

实现友盟分享

标签:des   style   http   os   io   for   cti   ar   

原文地址:http://www.cnblogs.com/xubojoy/p/3875523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!