Commit 38660331 by zhangyunjie

demo

parent c877ffec
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "ViewController.h" #import "ViewController.h"
#import "OffcnIMSDKiOS.h" #import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h" #import "OffcnIMSocketManager.h"
#import "OffcnIMZYJFMDBHandler.h" #import "OffcnIMZYJFMDBHandler.h"
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
//启动SDK //启动SDK
[[OffcnIMSDKiOS defaultService] setupWithIsTest:YES]; [[OffcnIMSDKiOS defaultService] setupWithIsTest:YES];
//推送 //注册推送
[AppDelegate registerOffcnUserNotificationSettingsWithApplication:application options:launchOptions]; [AppDelegate registerOffcnUserNotificationSettingsWithApplication:application options:launchOptions];
//获取用户相关数据库,该方法在登陆或者第一次启动已登陆下执行 //获取用户相关数据库,该方法在登陆或者第一次启动已登陆下执行
[[OffcnIMZYJFMDBHandler sharedInstance] getUserDB]; [[OffcnIMZYJFMDBHandler sharedInstance] getUserDB];
...@@ -82,24 +83,17 @@ ...@@ -82,24 +83,17 @@
// 25bb75ac 3ffcebd7 90d9f517 1ebca904 154a367a 87781e5d b9ea288e 37fdf487 // 25bb75ac 3ffcebd7 90d9f517 1ebca904 154a367a 87781e5d b9ea288e 37fdf487
NSLog(@"-----deviceToken ---- ---- %@ devDesc ---%@", deviceToken,deviceToken.description); NSLog(@"-----deviceToken ---- ---- %@ devDesc ---%@", deviceToken,deviceToken.description);
//解析deviceToken
NSString *str = [AppDelegate hexStringForData:deviceToken]; NSString *str = [AppDelegate hexStringForData:deviceToken];
[OffcnIMSDKiOS defaultService].deviceToken = str; [OffcnIMSDKiOS defaultService].deviceToken = str;
NSLog(@"token--- %@",str); NSLog(@"token--- %@",str);
//注册成功,返回token
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"APNS返回的Token:" message:str delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
// applicationIconBadgeNumber
} }
//注册失败 //注册失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"注册失败 ---- %@",error); NSLog(@"注册失败 ---- %@",error);
NSString *tokenStr = [NSString stringWithFormat:@"%@",error];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注册失败!" message:tokenStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
NSLog(@"注册失败%@",error);
} }
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
...@@ -107,10 +101,10 @@ ...@@ -107,10 +101,10 @@
NSLog(@"接收到远程推送通知Background ---- %@", userInfo); NSLog(@"接收到远程推送通知Background ---- %@", userInfo);
[AppDelegate didReceiveRemoteNotification:userInfo]; [AppDelegate didReceiveRemoteNotification:userInfo];
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { // if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
// [self pushNotificationDefaultController]; //
} // }
// Required, iOS 7 Support
completionHandler(UIBackgroundFetchResultNewData); completionHandler(UIBackgroundFetchResultNewData);
} }
...@@ -120,9 +114,9 @@ ...@@ -120,9 +114,9 @@
[AppDelegate didReceiveRemoteNotification:userInfo]; [AppDelegate didReceiveRemoteNotification:userInfo];
//将推送消息以alert形式呈现 //将推送消息以alert形式呈现
NSString *message = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"]; // NSString *message = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show]; // [alert show];
} }
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
NSLog(@"接收到本地推送通知 ---- %@", notification.userInfo); NSLog(@"接收到本地推送通知 ---- %@", notification.userInfo);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "OffcnIMSqliteTestVC.h" #import "OffcnIMSqliteTestVC.h"
#import "OffcnIMZYJFMDBHandler.h" #import "OffcnIMZYJFMDBHandler.h"
#import "OffcnIMModel.h" #import "OffcnIMModel.h"
#import "OffcnZYJTestDataStorageView.h" #import "OffcnZYJTestDataStorageView.h"
@interface OffcnIMSqliteTestVC () @interface OffcnIMSqliteTestVC ()
...@@ -72,8 +73,10 @@ ...@@ -72,8 +73,10 @@
for (int i=0; i<messagesArray.count; i++) { for (int i=0; i<messagesArray.count; i++) {
OffcnIMBodyModel *model = messagesArray[i]; OffcnIMBodyModel *model = messagesArray[i];
if (model.msg_type == 1) { if (model.msg_type == 1) {
//文本消息
msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"]; msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"];
}else{ }else{
//非文本消息
msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"]; msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"];
} }
...@@ -86,6 +89,8 @@ ...@@ -86,6 +89,8 @@
[storageView showView]; [storageView showView];
}]; }];
} }
//更新聊天列表未读数
- (IBAction)setUnreadNum:(UIButton *)sender { - (IBAction)setUnreadNum:(UIButton *)sender {
__block OffcnIMBodyModel *IMBodyModel = nil; __block OffcnIMBodyModel *IMBodyModel = nil;
......
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
// //
#import "OffcnZYJTestDataStorageView.h" #import "OffcnZYJTestDataStorageView.h"
#import "UIViewExt.h"
#import "SDGeneralDefine.h"
#import "DataSafe.h"
#import "SDGeneralTool.h"
@interface OffcnZYJTestDataStorageView () @interface OffcnZYJTestDataStorageView ()
...@@ -24,31 +20,31 @@ ...@@ -24,31 +20,31 @@
-(UIButton *)pasteBtn{ -(UIButton *)pasteBtn{
if (!_pasteBtn) { if (!_pasteBtn) {
_pasteBtn = [[UIButton alloc] init]; _pasteBtn = [[UIButton alloc] init];
_pasteBtn.titleLabel.font = KFontNameMediumSize(18); _pasteBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_pasteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_pasteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_pasteBtn setTitle:@"复制" forState:UIControlStateNormal]; [_pasteBtn setTitle:@"复制" forState:UIControlStateNormal];
[_pasteBtn addTarget:self action:@selector(pasteBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [_pasteBtn addTarget:self action:@selector(pasteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_pasteBtn.backgroundColor = KButtonSelectColor; _pasteBtn.backgroundColor = [UIColor redColor];
} }
return _pasteBtn; return _pasteBtn;
} }
-(void)pasteBtnAction:(UIButton *)button{ -(void)pasteBtnAction:(UIButton *)button{
KWeakSelf __weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = weakSelf.textView.text; pasteboard.string = weakSelf.textView.text;
[SDGeneralTool toastWithTitlemessage:@"复制成功"]; NSLog(@"复制成功");
}); });
} }
-(UIButton *)cancellBtn{ -(UIButton *)cancellBtn{
if (!_cancellBtn) { if (!_cancellBtn) {
_cancellBtn = [[UIButton alloc] init]; _cancellBtn = [[UIButton alloc] init];
_cancellBtn.titleLabel.font = KFontNameMediumSize(18); _cancellBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_cancellBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_cancellBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_cancellBtn setTitle:@"关闭" forState:UIControlStateNormal]; [_cancellBtn setTitle:@"关闭" forState:UIControlStateNormal];
[_cancellBtn addTarget:self action:@selector(closeBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [_cancellBtn addTarget:self action:@selector(closeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_cancellBtn.backgroundColor = KButtonSelectColor; _cancellBtn.backgroundColor = [UIColor redColor];
} }
return _cancellBtn; return _cancellBtn;
} }
...@@ -58,11 +54,11 @@ ...@@ -58,11 +54,11 @@
-(UITextView *)textView{ -(UITextView *)textView{
if (!_textView){ if (!_textView){
_textView = [[UITextView alloc] initWithFrame:CGRectZero]; _textView = [[UITextView alloc] initWithFrame:CGRectZero];
_textView.font = KFontNameMediumSize(13); _textView.font = [UIFont systemFontOfSize:13];
_textView.textColor = KTextColor; _textView.textColor = [UIColor greenColor];
_textView.textAlignment = NSTextAlignmentLeft; _textView.textAlignment = NSTextAlignmentLeft;
_textView.linkTextAttributes = @{NSForegroundColorAttributeName:UICOLOR_RGB_Alpha(0x4690f7, 1)}; _textView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]};
_textView.backgroundColor = [UIColor clearColor]; _textView.backgroundColor = [UIColor clearColor];
_textView.textContainer.lineFragmentPadding = 0; _textView.textContainer.lineFragmentPadding = 0;
_textView.textContainerInset = UIEdgeInsetsZero; _textView.textContainerInset = UIEdgeInsetsZero;
...@@ -86,13 +82,13 @@ ...@@ -86,13 +82,13 @@
-(void)layoutSubviews{ -(void)layoutSubviews{
[super layoutSubviews]; [super layoutSubviews];
self.textView.frame = CGRectMake(20, 0, self.width-40, self.height-30-20); self.textView.frame = CGRectMake(20, 0, self.frame.size.width-40, self.frame.size.height-30-20);
self.pasteBtn.frame = CGRectMake(20, CGRectGetMaxY(self.textView.frame)+10, (self.width-60)/2, 30); self.pasteBtn.frame = CGRectMake(20, CGRectGetMaxY(self.textView.frame)+10, (self.frame.size.width-60)/2, 30);
self.cancellBtn.frame = CGRectMake(CGRectGetMaxX(self.pasteBtn.frame)+20, self.pasteBtn.y, self.pasteBtn.width, self.pasteBtn.height); self.cancellBtn.frame = CGRectMake(CGRectGetMaxX(self.pasteBtn.frame)+20, self.pasteBtn.frame.origin.y, self.pasteBtn.frame.size.width, self.pasteBtn.frame.size.height);
} }
-(void)showView{ -(void)showView{
UIWindow *mainWindow = KKeyWindow; UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
[mainWindow addSubview:self]; [mainWindow addSubview:self];
[mainWindow bringSubviewToFront:self]; [mainWindow bringSubviewToFront:self];
[self setNeedsLayout]; [self setNeedsLayout];
...@@ -106,7 +102,6 @@ ...@@ -106,7 +102,6 @@
-(void)hidView{ -(void)hidView{
[self endEditing:YES]; [self endEditing:YES];
[self removeAllSubViews];
[self removeFromSuperview]; [self removeFromSuperview];
} }
@end @end
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
[self.timer setFireDate:[NSDate distantFuture]]; [self.timer setFireDate:[NSDate distantFuture]];
} }
//压力测试
-(void)loop{ -(void)loop{
NSString *randomStr = [NSString stringWithFormat:@"zyj%d",arc4random_uniform(1000000)]; NSString *randomStr = [NSString stringWithFormat:@"zyj%d",arc4random_uniform(1000000)];
[[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:OffcnSDKMsgTypeText text:randomStr filePath:nil Finished:^(BOOL success, OffcnIMSendMsgModel *sendMsgModel, NSString *errorMessage) { [[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:OffcnSDKMsgTypeText text:randomStr filePath:nil Finished:^(BOOL success, OffcnIMSendMsgModel *sendMsgModel, NSString *errorMessage) {
...@@ -85,6 +87,7 @@ ...@@ -85,6 +87,7 @@
//建立连接 //建立连接
[[OffcnIMSocketManager defaultService] connectIMServerWithAccount_id:self.fromId token:self.sendTokenTextField.text]; [[OffcnIMSocketManager defaultService] connectIMServerWithAccount_id:self.fromId token:self.sendTokenTextField.text];
//收到消息回调
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[OffcnIMSocketManager defaultService].connectReceiveMessage = ^(OffcnIMModel *IMModel) { [OffcnIMSocketManager defaultService].connectReceiveMessage = ^(OffcnIMModel *IMModel) {
NSLog(@"收到消息---%@,时间:%@",IMModel.body.msg.msg,IMModel.body.send_time); NSLog(@"收到消息---%@,时间:%@",IMModel.body.msg.msg,IMModel.body.send_time);
...@@ -100,6 +103,7 @@ ...@@ -100,6 +103,7 @@
// [weakSelf tipMessageWithTitle:@"收到消息" message:msg]; // [weakSelf tipMessageWithTitle:@"收到消息" message:msg];
}; };
//收到连接状态回调
[OffcnIMSocketManager defaultService].connectStatus = ^(OffcnIMConnectStatus status, NSString * _Nonnull errorMessage) { [OffcnIMSocketManager defaultService].connectStatus = ^(OffcnIMConnectStatus status, NSString * _Nonnull errorMessage) {
NSLog(@"收到连接状态---%@,code:%lu,%@",errorMessage,(unsigned long)status,[weakSelf getNowSSSTimeTimestamp]); NSLog(@"收到连接状态---%@,code:%lu,%@",errorMessage,(unsigned long)status,[weakSelf getNowSSSTimeTimestamp]);
if (status == OffcnIMConnectStatusDisConnectOK) { if (status == OffcnIMConnectStatusDisConnectOK) {
...@@ -175,8 +179,10 @@ ...@@ -175,8 +179,10 @@
for (int i=0; i<unreadMsgModel.msg_list.count; i++) { for (int i=0; i<unreadMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = unreadMsgModel.msg_list[i]; OffcnIMBodyModel *model = unreadMsgModel.msg_list[i];
if (model.msg_type == 1) { if (model.msg_type == 1) {
//文本消息
msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"]; msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"];
}else{ }else{
//非文本消息
msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"]; msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"];
} }
...@@ -214,8 +220,10 @@ ...@@ -214,8 +220,10 @@
OffcnIMSessionModel *model = recentMsgModel.sessions[i]; OffcnIMSessionModel *model = recentMsgModel.sessions[i];
if (model.last_msg.msg_type == 1) { if (model.last_msg.msg_type == 1) {
//文本消息
msg = [msg stringByAppendingString:model.last_msg.msg_content.msg?model.last_msg.msg_content.msg:@"nil"]; msg = [msg stringByAppendingString:model.last_msg.msg_content.msg?model.last_msg.msg_content.msg:@"nil"];
}else{ }else{
//非文本消息
msg = [msg stringByAppendingString:model.last_msg.msg_content.url?model.last_msg.msg_content.url:@"nil"]; msg = [msg stringByAppendingString:model.last_msg.msg_content.url?model.last_msg.msg_content.url:@"nil"];
} }
...@@ -241,8 +249,10 @@ ...@@ -241,8 +249,10 @@
for (int i=0; i<historyMsgModel.msg_list.count; i++) { for (int i=0; i<historyMsgModel.msg_list.count; i++) {
OffcnIMBodyModel *model = historyMsgModel.msg_list[i]; OffcnIMBodyModel *model = historyMsgModel.msg_list[i];
if (model.msg_type == 1) { if (model.msg_type == 1) {
//文本消息
msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"]; msg = [msg stringByAppendingString:model.msg.msg?model.msg.msg:@"nil"];
}else{ }else{
//非文本消息
msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"]; msg = [msg stringByAppendingString:model.msg.url?model.msg.url:@"nil"];
} }
......
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