评论 详细集成

注意:本文示例代码均针对最新版SDK,如果你所用SDK的类名或方法名与此文不符合,请使用你所用SDK的随包文档、或者下载使用最新版SDK。

1 评论界面方法

//把你的文章或者音乐的标识,作为@"identifier"
UMSocialData *socialData = [[UMSocialData alloc] initWithIdentifier:@"identifier"];
UMSocialControllerServiceComment *socialControllerService = [[UMSocialControllerServiceComment alloc] initWithUMSocialData:socialData];
UINavigationController *commentList = [socialControllerService getSocialCommentListController];
[self presentModalViewController:commentList animated:YES];

socialbar

socialData.commentText = @"评论内嵌文字";
socialData.commentImage = [UIImage imageNamed:@"icon.png"];

2 评论数据方法

//把你的文章或者音乐的标识,作为@"identifier"
UMSocialData *socialData = [[UMSocialData alloc] initWithIdentifier:@"identifier"];
UMSocialDataService *socialDataService = [[UMSocialDataService alloc] initWithUMSocialData:socialData];
//如果不区分评论内容的话可以用默认初始化方法
//UMSocialDataService *socialDataService = [UMSocialDataService defaultDataService];
//如果评论数据比较多,想获取之前的评论,可以在`lastCommentTime`中传入指定时间戳。传入评论数据在回调Block对象形参response里的属性`data`中得到
//socialDataService为设置评论内容中初始化的对象
[socialDataService requestCommentList:(-1) completion:^(UMSocialResponseEntity *response){
            NSLog(@"comment data is %@",response.data);
        }];
//socialDataService为设置评论内容中初始化的对象
[socialDataService postCommentWithContent:@"comment text" completion:^(UMSocialResponseEntity *response){
   NSLog(@"comment result is %@",response);
        }];
//socialDataService为设置评论内容中初始化的对象
[socialDataService postCommentWithContent:@"评论内容" image:nil templateText:@"评论并分享到微博后面带的内容" location:nil shareToSNSWithUsid:nil completion:nil];
//如果要评论并分享到微博需要形如下面的微博平台名和微博用户usid组成的NSDictionary,传入到上面的shareToSNSWithUsid:参数中
//NSString *usid = [[[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina] usid];  //得到已经授权的usid,可以把UMShareToSina替换为代表其他平台的字符串   
//NSDictionary *shareToSNS = [NSDictionary dictionaryWithObjectsAndKeys:usid,UMShareToSina,nil];
//socialDataService为设置评论内容中初始化的对象    
    [socialDataService requestSocialDataWithCompletion:^(UMSocialResponseEntity *response){
// 下面的方法可以获取保存在本地的评论数,如果app重新安装之后,数据会被清空,可能获取值为0
        int commentNumber = [socialDataService.socialData getNumber:UMSNumberComment];
        NSLog(@"commentNum is %d",commentNumber);
    }];

常见错误代码含义

错误码 错误原因
503 评论失败
504 获取评论失败