融云聊天室自定義cell

15年寫(xiě)的代碼,現(xiàn)在都忘記了,看了好多人問(wèn)關(guān)于這方面的問(wèn)題,把以前的代碼給大家做個(gè)參考

#import "RCDChatViewController.h"
#import "ChatListViewController.h"
#import "XiangQingViewController.h"

#import <RongIMKit/RongIMKit.h>
@interface RCDChatViewController ()
//<
//    UIActionSheetDelegate, RCRealTimeLocationObserver,
//    RealTimeLocationStatusViewDelegate, UIAlertViewDelegate,
//    RCMessageCellDelegate>
//@property(nonatomic, weak) id<RCRealTimeLocationProxy> realTimeLocation;
//@property(nonatomic, strong)
//    RealTimeLocationStatusView *realTimeLocationStatusView;
//@property(nonatomic, strong) RCDGroupInfo *groupInfo;

//-(UIView *)loadEmoticonView:(NSString *)identify index:(int)index;
@end

NSMutableDictionary *userInputStatus;

@implementation RCDChatViewController

//隱藏uitabar底部欄
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([self.targetId isEqualToString:@"6666-6666-6666-6666-6666"]) {
        self.chatSessionInputBarControl.hidden = YES;
        self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
    }
}

- (void) viewDidLoad{
    [super viewDidLoad];
    [self.pluginBoardView removeItemWithTag:1003];
//    [self.pluginBoardView removeItemWithTag:1101];
//    [self.pluginBoardView removeItemWithTag:1102];
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 6, 87, 23);
    UIImageView *backImg = [[UIImageView alloc]
                            initWithImage:[UIImage imageNamed:@"icon_back"]];
    backImg.frame = CGRectMake(-6, 4, 10, 17);
    [backBtn addSubview:backImg];
    [backBtn addTarget:self
                action:@selector(leftBarButtonItemPressed:)
      forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButton =
    [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    // 1.獲取當(dāng)前的版本號(hào)
    NSString *currentVersion = self.token_Id;
    // 2.獲取上一次的版本號(hào)
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:FirstPostMessageUserId];
    // 判斷當(dāng)前是否有新的版本
    if (![currentVersion isEqualToString:lastVersion]) { // 沒(méi)有最新的版本號(hào)
        [self postFirstMessage];
        // 保持當(dāng)前的版本,用偏好設(shè)置
        [[NSUserDefaults standardUserDefaults] setObject:self.token_Id forKey:FirstPostMessageUserId];
    }
}

- (void) postFirstMessage{
    NSURLSession *session = [NSURLSession sharedSession];
    //2.根據(jù)NSURLSession對(duì)象創(chuàng)建一個(gè)Task
    NSURL *url = [NSURL URLWithString:@"http://data.xiongmao999.com/jy_app/index.php/Rongyun/AutoReply"];
    //創(chuàng)建一個(gè)請(qǐng)求對(duì)象,并這是請(qǐng)求方法為POST,把參數(shù)放在請(qǐng)求體中傳遞
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"POST";
    request.HTTPBody = [[NSString stringWithFormat:@"hardware_sn=%@&userId=%@",adId,self.token_Id] dataUsingEncoding:NSUTF8StringEncoding];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * __nullable data, NSURLResponse * __nullable response, NSError * __nullable error) {
        if (!error) {
            NSError *err;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data
                                                                options:NSJSONReadingMutableContainers
                                                                  error:&err];
        }
    }];
    //3.執(zhí)行Task
    //注意:剛創(chuàng)建出來(lái)的task默認(rèn)是掛起狀態(tài)的,需要調(diào)用該方法來(lái)啟動(dòng)任務(wù)(執(zhí)行任務(wù))
    [dataTask resume];
}

- (void)leftBarButtonItemPressed:(id)sender {
    //需要調(diào)用super的實(shí)現(xiàn)
    [super leftBarButtonItemPressed:sender];
    
    [self.navigationController popViewControllerAnimated:YES];
}
//即將發(fā)送消息
- (RCMessageContent *)willSendMessage:(RCMessageContent *)messageCotent {
//    RCUserInfo *senderUserInfo = messageCotent.senderUserInfo;
    //可以在這里修改將要發(fā)送的消息
    NSString * vip = [SAMKeychain passwordForService:@"" account:kUserVip];
    if ([vip isEqualToString:@"notvip"]) {
        NSString * messageCount = [SAMKeychain passwordForService:@"" account:self.userName];
        if (messageCount == nil) {
            [SAMKeychain setPassword:@"1" forService:@"" account:self.userName];
            return messageCotent;
        }else{
#warning 跳轉(zhuǎn)到購(gòu)買(mǎi)的界面
            BUYViewController * chatListVC = [[BUYViewController alloc] init];
            [self.navigationController pushViewController:chatListVC animated:YES];
            return nil;
        }
    }else{
       return messageCotent;
    }
}

- (void)didTapCellPortrait:(NSString *)userId {
    NSLog(@"這里要跳轉(zhuǎn)到個(gè)人界面");
    NSURLSession *session = [NSURLSession sharedSession];
    //2.根據(jù)NSURLSession對(duì)象創(chuàng)建一個(gè)Task
    NSURL *url = [NSURL URLWithString:@"http://data.xiongmao999.com/jy_app/index.php/User/get_user_type"];
    //創(chuàng)建一個(gè)請(qǐng)求對(duì)象,并這是請(qǐng)求方法為POST,把參數(shù)放在請(qǐng)求體中傳遞
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"POST";
    request.HTTPBody = [[NSString stringWithFormat:@"userId=%@",userId] dataUsingEncoding:NSUTF8StringEncoding];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * __nullable data, NSURLResponse * __nullable response, NSError * __nullable error) {
        if (!error) {
            NSError *err;
            NSArray *typeArray = [NSJSONSerialization JSONObjectWithData:data
                                                                options:NSJSONReadingMutableContainers
                                                                  error:&err];
            NSString * userType = [typeArray valueForKey:@"type"];
            NSString * user_Id = [typeArray valueForKey:@"id"];
            if ([userType isEqualToString:@"2"]) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    XiangQingViewController *detail = [[XiangQingViewController alloc]init];
                    detail.sspid = user_Id;
                    detail.hidden_lianxita = YES;
                    [self.navigationController pushViewController:detail animated:YES];
                });
            }else{
                
            }
        }
    }];
    //3.執(zhí)行Task
    //注意:剛創(chuàng)建出來(lái)的task默認(rèn)是掛起狀態(tài)的,需要調(diào)用該方法來(lái)啟動(dòng)任務(wù)(執(zhí)行任務(wù))
    [dataTask resume];
}
#pragma mark  圖片1001 拍照1002 1101是語(yǔ)音通話 1102 是視頻通話
-(void)pluginBoardView:(RCPluginBoardView*)pluginBoardView clickedItemWithTag:(NSInteger)tag{
    NSString * vip = [SAMKeychain passwordForService:@"" account:kUserVip];
    if ([vip isEqualToString:@"notvip"]) {
        BUYViewController * chatListVC = [[BUYViewController alloc] init];
        [self.navigationController pushViewController:chatListVC animated:YES];
    }else{
        [super pluginBoardView:pluginBoardView clickedItemWithTag:tag];
    }
}

@end

已經(jīng)做安卓好幾年了,iOS的知識(shí)多多少少忘了一些。。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容