實現友盟分享

weixin_30639719發表於2020-04-05

-(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);

                

                

            }

        }];

    }

}

轉載於:https://www.cnblogs.com/xubojoy/p/3875523.html

相關文章