15年写的代码,现在都忘记了,看了好多人问关于这方面的问题,把以前的代码给大家做个参考
#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.获取当前的版本号
NSString *currentVersion = self.token_Id;
// 2.获取上一次的版本号
NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:FirstPostMessageUserId];
// 判断当前是否有新的版本
if (![currentVersion isEqualToString:lastVersion]) { // 没有最新的版本号
[self postFirstMessage];
// 保持当前的版本,用偏好设置
[[NSUserDefaults standardUserDefaults] setObject:self.token_Id forKey:FirstPostMessageUserId];
}
}
- (void) postFirstMessage{
NSURLSession *session = [NSURLSession sharedSession];
//2.根据NSURLSession对象创建一个Task
NSURL *url = [NSURL URLWithString:@"http://data.xiongmao999.com/jy_app/index.php/Rongyun/AutoReply"];
//创建一个请求对象,并这是请求方法为POST,把参数放在请求体中传递
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.执行Task
//注意:刚创建出来的task默认是挂起状态的,需要调用该方法来启动任务(执行任务)
[dataTask resume];
}
- (void)leftBarButtonItemPressed:(id)sender {
//需要调用super的实现
[super leftBarButtonItemPressed:sender];
[self.navigationController popViewControllerAnimated:YES];
}
//即将发送消息
- (RCMessageContent *)willSendMessage:(RCMessageContent *)messageCotent {
// RCUserInfo *senderUserInfo = messageCotent.senderUserInfo;
//可以在这里修改将要发送的消息
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 跳转到购买的界面
BUYViewController * chatListVC = [[BUYViewController alloc] init];
[self.navigationController pushViewController:chatListVC animated:YES];
return nil;
}
}else{
return messageCotent;
}
}
- (void)didTapCellPortrait:(NSString *)userId {
NSLog(@"这里要跳转到个人界面");
NSURLSession *session = [NSURLSession sharedSession];
//2.根据NSURLSession对象创建一个Task
NSURL *url = [NSURL URLWithString:@"http://data.xiongmao999.com/jy_app/index.php/User/get_user_type"];
//创建一个请求对象,并这是请求方法为POST,把参数放在请求体中传递
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.执行Task
//注意:刚创建出来的task默认是挂起状态的,需要调用该方法来启动任务(执行任务)
[dataTask resume];
}
#pragma mark 图片1001 拍照1002 1101是语音通话 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
已经做安卓好几年了,iOS的知识多多少少忘了一些。。。。