Commit c98d5890 by zhangyunjie

demo

parent e9673ded
......@@ -208,6 +208,7 @@
A9D1B31824EFAD8C000F4662 /* OffcnUploadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D1B31724EFAD8C000F4662 /* OffcnUploadManager.m */; };
A9D1B31B24F34C25000F4662 /* OffcnIMSocketManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D1B31A24F34C25000F4662 /* OffcnIMSocketManager.m */; };
A9D1B32224F50973000F4662 /* OffcnIMModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D1B32124F50973000F4662 /* OffcnIMModel.m */; };
A9D1B32E24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D1B32C24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.m */; };
B94FCB1053F8932068A11CC9 /* libPods-OffcnIMSDKiOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 49CE5E230A14D9B821170F61 /* libPods-OffcnIMSDKiOS.a */; };
/* End PBXBuildFile section */
......@@ -644,6 +645,8 @@
A9D1B31A24F34C25000F4662 /* OffcnIMSocketManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffcnIMSocketManager.m; sourceTree = "<group>"; };
A9D1B32024F50973000F4662 /* OffcnIMModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OffcnIMModel.h; sourceTree = "<group>"; };
A9D1B32124F50973000F4662 /* OffcnIMModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffcnIMModel.m; sourceTree = "<group>"; };
A9D1B32C24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OffcnZYJTestDataStorageView.m; sourceTree = "<group>"; };
A9D1B32D24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OffcnZYJTestDataStorageView.h; sourceTree = "<group>"; };
D7DCDED1DEE7F99F223D5C73 /* Pods-OffcnIMSDKiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OffcnIMSDKiOS.release.xcconfig"; path = "Target Support Files/Pods-OffcnIMSDKiOS/Pods-OffcnIMSDKiOS.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -704,6 +707,8 @@
A9661B5E24EA72900024EB54 /* AppDelegate.m */,
A9661B5D24EA72900024EB54 /* ViewController.h */,
A9661B5F24EA72900024EB54 /* ViewController.mm */,
A9D1B32D24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.h */,
A9D1B32C24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.m */,
A9661B6224EA729A0024EB54 /* Main.storyboard */,
A9661B4F24EA64F20024EB54 /* Assets.xcassets */,
A9661B5124EA64F20024EB54 /* LaunchScreen.storyboard */,
......@@ -1635,6 +1640,7 @@
A9661FD924EA7AD10024EB54 /* SDButton.m in Sources */,
A966219024EA80A60024EB54 /* ZYJMJRefreshAutoNormalFooter.m in Sources */,
A96621CA24EA80A60024EB54 /* ZYJMQTTCFSocketEncoder.m in Sources */,
A9D1B32E24F7BE7B000F4662 /* OffcnZYJTestDataStorageView.m in Sources */,
A966218224EA80A60024EB54 /* ZYJSDWebImagePrefetcher.m in Sources */,
A966216B24EA80A60024EB54 /* ZYJPingHelper.m in Sources */,
A966217324EA80A60024EB54 /* ZYJReachStateWIFI.m in Sources */,
......
//
//
......@@ -61,6 +61,10 @@ static OffcnIMSocketManager *socketManager;
NSString *revStr = [NSString stringWithUTF8String:message];
OffcnIMModel *IMModel = [OffcnIMModel mj_ZYJobjectWithKeyValues:revStr];
NSString *msg_id = IMModel.body.msg_id;
if (!msg_id) {
return;
}
if (self.msgArr.count) {
if ([self.msgArr containsObject:msg_id]) {
//消息重复,丢弃
......@@ -71,6 +75,7 @@ static OffcnIMSocketManager *socketManager;
[self.msgArr addObject:msg_id];
//存数据库
if (self.connectReceiveMessage) {
self.connectReceiveMessage(IMModel);
}
......@@ -78,6 +83,8 @@ static OffcnIMSocketManager *socketManager;
}else{
[self.msgArr addObject:msg_id];
//存数据库
if (self.connectReceiveMessage) {
self.connectReceiveMessage(IMModel);
}
......
//
// OffcnZYJTestDataStorageView.h
// OffcnLiveSDK
//
// Created by zyj on 2020/3/28.
// Copyright © 2020 中公教育. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface OffcnZYJTestDataStorageView : UIView
@property (nonatomic, strong) NSString *msg;
-(instancetype)initWithFrame:(CGRect)frame;
-(void)showView;
-(void)hidView;
@end
NS_ASSUME_NONNULL_END
//
// OffcnZYJTestDataStorageView.m
// OffcnLiveSDK
//
// Created by zyj on 2020/3/28.
// Copyright © 2020 中公教育. All rights reserved.
//
#import "OffcnZYJTestDataStorageView.h"
#import "UIViewExt.h"
#import "SDGeneralDefine.h"
#import "DataSafe.h"
#import "SDGeneralTool.h"
@interface OffcnZYJTestDataStorageView ()
@property (nonatomic, strong) UIButton *pasteBtn;
@property (nonatomic, strong) UIButton *cancellBtn;
@property (nonatomic, strong) UITextView *textView;
@end
@implementation OffcnZYJTestDataStorageView
-(UIButton *)pasteBtn{
if (!_pasteBtn) {
_pasteBtn = [[UIButton alloc] init];
_pasteBtn.titleLabel.font = KFontNameMediumSize(18);
[_pasteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_pasteBtn setTitle:@"复制" forState:UIControlStateNormal];
[_pasteBtn addTarget:self action:@selector(pasteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_pasteBtn.backgroundColor = KButtonSelectColor;
}
return _pasteBtn;
}
-(void)pasteBtnAction:(UIButton *)button{
KWeakSelf
dispatch_async(dispatch_get_main_queue(), ^{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = weakSelf.textView.text;
[SDGeneralTool toastWithTitlemessage:@"复制成功"];
});
}
-(UIButton *)cancellBtn{
if (!_cancellBtn) {
_cancellBtn = [[UIButton alloc] init];
_cancellBtn.titleLabel.font = KFontNameMediumSize(18);
[_cancellBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_cancellBtn setTitle:@"关闭" forState:UIControlStateNormal];
[_cancellBtn addTarget:self action:@selector(closeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_cancellBtn.backgroundColor = KButtonSelectColor;
}
return _cancellBtn;
}
-(void)closeBtnAction:(UIButton *)button{
[self hidView];
}
-(UITextView *)textView{
if (!_textView){
_textView = [[UITextView alloc] initWithFrame:CGRectZero];
_textView.font = KFontNameMediumSize(13);
_textView.textColor = KTextColor;
_textView.textAlignment = NSTextAlignmentLeft;
_textView.linkTextAttributes = @{NSForegroundColorAttributeName:UICOLOR_RGB_Alpha(0x4690f7, 1)};
_textView.backgroundColor = [UIColor clearColor];
_textView.textContainer.lineFragmentPadding = 0;
_textView.textContainerInset = UIEdgeInsetsZero;
_textView.editable = NO;
_textView.scrollEnabled = YES;
_textView.dataDetectorTypes = UIDataDetectorTypeLink;
}
return _textView;
}
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
[self addSubview:self.pasteBtn];
[self addSubview:self.cancellBtn];
[self addSubview:self.textView];
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
self.textView.frame = CGRectMake(20, 0, self.width-40, self.height-30-20);
self.pasteBtn.frame = CGRectMake(20, CGRectGetMaxY(self.textView.frame)+10, (self.width-60)/2, 30);
self.cancellBtn.frame = CGRectMake(CGRectGetMaxX(self.pasteBtn.frame)+20, self.pasteBtn.y, self.pasteBtn.width, self.pasteBtn.height);
}
-(void)showView{
UIWindow *mainWindow = KKeyWindow;
[mainWindow addSubview:self];
[mainWindow bringSubviewToFront:self];
[self setNeedsLayout];
[self layoutIfNeeded];
}
-(void)setMsg:(NSString *)msg{
_msg = msg;
self.textView.text = msg;
}
-(void)hidView{
[self endEditing:YES];
[self removeAllSubViews];
[self removeFromSuperview];
}
@end
......@@ -12,6 +12,7 @@
#import "OffcnNetworkExecutor.h"
#import "SDGeneralTool.h"
#import "OffcnZYJTestDataStorageView.h"
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
......@@ -46,18 +47,30 @@
NSString *paramStr = @"{\"server_ip\":\"39.102.42.185\", \"server_port\":6000, \"user_id\":\"ce0819db8391f1e7258a71cc9e2c3235\",\"app_id\":\"offcn_live\", \"device_type\":\"ios\", \"token\":\"fadbce3f4929b6bdee0617fee34e32ae\"}";
[[OffcnIMSocketManager defaultService] connectIMServerWithParam:paramStr];
__weak typeof(self) weakSelf = self;
[OffcnIMSocketManager defaultService].connectReceiveMessage = ^(OffcnIMModel *IMModel) {
NSLog(@"收到消息---%@",IMModel.body.msg.msg);
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收到消息" message:IMModel.body.msg.msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
});
NSString *msg = @"";
if (IMModel.body.msg_type == 1) {
msg = [msg stringByAppendingString:IMModel.body.msg.msg?IMModel.body.msg.msg:@"nil"];
}else{
msg = [msg stringByAppendingString:IMModel.body.msg.url?IMModel.body.msg.url:@"nil"];
}
[weakSelf tipMessageWithTitle:@"收到消息" message:msg];
};
[OffcnIMSocketManager defaultService].connectStatus = ^(OffcnIMConnectStatus status, NSString * _Nonnull errorMessage) {
NSLog(@"收到连接状态---%@,code:%lu",errorMessage,(unsigned long)status);
if (status == OffcnIMConnectStatusDisConnectOK) {
errorMessage = @"断开连接成功";
}else if (status == OffcnIMConnectStatusSuccess){
errorMessage = @"连接成功";
}else if (status == OffcnIMConnectStatusFail){
errorMessage = @"连接失败,请重新连接";
}else if (status == OffcnIMConnectStatusBreak){
errorMessage = @"连接断开,请重新连接";
}
[weakSelf tipMessageWithTitle:@"收到连接状态" message:errorMessage];
};
}
......@@ -67,54 +80,138 @@
}
- (IBAction)sendMegAction:(UIButton *)sender {
//暂无
[self tipMessageWithTitle:@"暂无此功能" message:@""];
}
//发送本地通知
- (IBAction)sendLocalNotiAction:(UIButton *)sender {
//暂无
[self tipMessageWithTitle:@"暂无此功能" message:@""];
}
- (IBAction)sendMeg:(UIButton *)sender {
//发送消息
__weak typeof(self) weakSelf = self;
NSString *tidStr = [NSString stringWithFormat:@"%@_%@",self.toId,[SDGeneralTool getNowSSSTimeTimestamp]];
[[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId tid:tidStr msg_type:OffcnSDKMsgTypeText text:@"你好" filePath:nil Finished:^(BOOL success, OffcnIMSendMsgModel *sendMsgModel, NSString *errorMessage) {
if (success) {
[weakSelf tipMessageWithTitle:@"发送消息成功" message:@""];
}else{
[weakSelf tipMessageWithTitle:@"发送消息失败" message:errorMessage];
}
}];
}
- (IBAction)noReadListAction:(UIButton *)sender {
//获取会话未读消息列表
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] getSessionUnreadMsgWithFromID:self.fromId toID:self.toId Finished:^(BOOL success, OffcnIMUnreadMsgModel *unreadMsgModel, NSString *errorMessage) {
if (success) {
NSString *msg = @"";
for (int i=0; i<unreadMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = unreadMsgModel.msg_list[i];
if (model.msg_type == 1) {
msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"];
}else{
msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"];
}
msg = [msg stringByAppendingString:@"\r\n"];
}
OffcnZYJTestDataStorageView *storageView = [[OffcnZYJTestDataStorageView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-20)];
storageView.msg = msg;
[storageView showView];
}else{
[weakSelf tipMessageWithTitle:@"获取会话未读消息列表失败" message:errorMessage];
}
}];
}
- (IBAction)readedAction:(UIButton *)sender {
//用户信息标记已读
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] markMsgReadWithMsg_fromID:self.fromId msg_toID:self.toId msg_seq:1597744585 Finished:^(BOOL success, id response, NSString *errorMessage) {
if (success) {
[weakSelf tipMessageWithTitle:@"标记已读成功" message:@""];
}else{
[weakSelf tipMessageWithTitle:@"标记已读失败" message:errorMessage];
}
}];
}
- (IBAction)recentVChatAction:(UIButton *)sender {
//获取用户最近会话记录
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] getRecentSessionsWithAccid:self.fromId Finished:^(BOOL success, OffcnIMRecentMsgModel *recentMsgModel, NSString *errorMessage) {
if (success) {
NSString *msg = @"";
for (int i=0; i<recentMsgModel.sessions.count; i++) {
OffcnIMSessionModel *model = recentMsgModel.sessions[i];
if (model.last_msg.msg_type == 1) {
msg = [msg stringByAppendingString:model.last_msg.msg_content.msg?model.last_msg.msg_content.msg:@"nil"];
}else{
msg = [msg stringByAppendingString:model.last_msg.msg_content.url?model.last_msg.msg_content.url:@"nil"];
}
msg = [msg stringByAppendingString:@"\r\n"];
}
OffcnZYJTestDataStorageView *storageView = [[OffcnZYJTestDataStorageView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-20)];
storageView.msg = msg;
[storageView showView];
}else{
[weakSelf tipMessageWithTitle:@"获取用户最近会话记录失败" message:errorMessage];
}
}];
}
- (IBAction)historyMegListAction:(UIButton *)sender {
//获取会话历史消息列表
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] getSessionHistoryMsgWithFromID:self.fromId toID:self.toId msg_seq:@"" Finished:^(BOOL success, OffcnIMHistoryMsgModel *historyMsgModel, NSString *errorMessage) {
if (success) {
NSString *msg = @"";
for (int i=0; i<historyMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = historyMsgModel.msg_list[i];
if (model.msg_type == 1) {
msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"];
}else{
msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"];
}
msg = [msg stringByAppendingString:@"\r\n"];
}
OffcnZYJTestDataStorageView *storageView = [[OffcnZYJTestDataStorageView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-20)];
storageView.msg = msg;
[storageView showView];
}else{
[weakSelf tipMessageWithTitle:@"获取会话历史消息列表失败" message:errorMessage];
}
}];
}
- (IBAction)registeredUser:(UIButton *)sender {
//注册用户设备
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] registerDevicesWithAccid:self.fromId device_token:[OffcnIMSDKiOS defaultService].deviceToken Finished:^(BOOL success, id response, NSString *errorMessage) {
if (success) {
[weakSelf tipMessageWithTitle:@"注册用户设备成功" message:@""];
}else{
[weakSelf tipMessageWithTitle:@"注册用户设备失败" message:errorMessage];
}
}];
}
- (IBAction)UnRegisteredUser:(UIButton *)sender {
//注销用户设备
__weak typeof(self) weakSelf = self;
[[OffcnIMSDKiOS defaultService] unregisterDevicesWithAccid:self.fromId device_token:[OffcnIMSDKiOS defaultService].deviceToken Finished:^(BOOL success, id response, NSString *errorMessage) {
if (success) {
[weakSelf tipMessageWithTitle:@"注销用户设备成功" message:@""];
}else{
[weakSelf tipMessageWithTitle:@"注销用户设备失败" message:errorMessage];
}
}];
}
......@@ -125,9 +222,16 @@
- (IBAction)uploadFile:(UIButton *)sender {
//上传
__weak typeof(self) weakSelf = self;
NSString *tidStr = [NSString stringWithFormat:@"%@_%@",self.toId,[SDGeneralTool getNowSSSTimeTimestamp]];
NSString *filePath = [self getImagePath:self.pickImage];
[[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId tid:@"" msg_type:OffcnSDKMsgTypePicture text:nil filePath:filePath Finished:^(BOOL success, OffcnIMSendMsgModel *sendMsgModel, NSString *errorMessage) {
[[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId tid:tidStr msg_type:OffcnSDKMsgTypePicture text:nil filePath:filePath Finished:^(BOOL success, OffcnIMSendMsgModel *sendMsgModel, NSString *errorMessage) {
if (success) {
[weakSelf tipMessageWithTitle:@"上传成功" message:@""];
}else{
[weakSelf tipMessageWithTitle:@"上传失败" message:errorMessage];
}
}];
}
......@@ -163,6 +267,7 @@
} else {
//访问相册错误
NSLog(@"访问相册错误");
[self tipMessageWithTitle:@"访问相册错误" message:@""];
}
}
//照片获取本地路径转换
......@@ -192,6 +297,13 @@
return filePath;
}
-(void)tipMessageWithTitle:(NSString *)title message:(NSString *)message{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
});
}
//可旋转屏幕
- (BOOL)shouldAutorotate {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment