`
haoningabc
  • 浏览: 1482583 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

facebook的socketrocket总结

    博客分类:
  • ios
阅读更多
最近看了开源的网易的demo
https://netease.im/
关键类
NTESSessionViewController.m
发送函数
#pragma mark - 消息发送时间截获
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error

NIMSessionViewController.m
接收消息函数
//接收消息
- (void)onRecvMessages:(NSArray *)messages




############

ld: warning: directory not found for option

brew install cocoapods


xcode-select --switch /Applications/Xcode.app

pod install


https://stackoverflow.com/questions/24050012/error-library-not-found-for

I had a similar "library not found" issue. However it was because I accidentally was using the .xcodeproj file instead of the .xcworkspace file.



###########
推送问题

Cannot create a iOS App Development provisioning profile for "com.haoning.demo123121".
Your development team, "leaf french", does not support the Push Notifications capability.

NIMDev.entitlements

<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
改成
<dict>
</dict>

https://stackoverflow.com/questions/44568009/how-to-disable-push-notification-capability-in-xcode-project


Xcode 运行项目时候选择模拟器位置处显示"My Mac" 的处理

1、先关闭Xcode,找到该工程项目目录,找到该项目的***.xcodeproj 文件,然后右键点击选择“显示包内容”;
2、包内容中显示以下三项:project.pbxproj .project.xcworkspace .xcuserdata 接着选择“xcuserdata”这个文件夹,将其整个移到废纸篓,重新打开你的项目,则可使用Simulator;
3、如果上诉方法没有用, 那么找到target->built settings->Architectures->Base SDK.这里改成你需要的iOS版本即可。


iOS 报错:cannot create weak reference in file using
http://blog.csdn.net/u010545480/article/details/52995908



SocketRocket must be compiled with ARC enabled
https://jingyan.baidu.com/article/358570f67babbcce4724fcd8.html
build settings搜ARC



#pragma mark - 消息发送时间截获
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error
{
    printf("sendMessage---->hello hit me!!\n");
   // NSString *message_temp = @"aaa";
    //message =  mytext.text;
   // [_webSocket send:message_temp];
    
    [_webSocket send:message.text];
    
    
//  printf("------->sendMessage--begin----->\n");
    NSLog(@"---NTESSessionViewController-->sendMessage----->>>>>>%@",message);
//  printf("------->sendMessage--end----->\n");




1。新建target framework & Library ,选Cocoa Touch Static Library 文字为SocketRocket
2。SRWebSocket.h 和.m覆盖过来
3.编译完SocketRocket的target
4.切换到im的target,爸libsocketrockt.a作为build Phrase的link binary with library引入进来
,还要引入foundtion.framework Security.framework CFNetwork.framework
3.ViewController引入
#import "SRWebSocket.h"
@interface ViewController () <SRWebSocketDelegate>

@end
@implementation ViewController {
    SRWebSocket *_webSocket;
    NSMutableArray *_messages;
}

报错引入各种接口

- (void)viewDidLoad {
    [super viewDidLoad];
    printf("haha begin--> \n");
    _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://localhost:3001"]]];
    
    _webSocket.delegate = self;
    [_webSocket open];
    
    [NSThread sleepForTimeInterval:0.1f];
    printf("haha   open--> \n");
    NSString *message = @"aaa";
    [_webSocket send:message];
   
    
    
    [_webSocket close];
    printf("haha   close--> \n");
    printf("haha   end--> \n");
    // Do any additional setup after loading the view, typically from a nib.
}


4.
Installing (iOS)
----------------
There's a few options. Choose one, or just figure it out

- You can copy all the files in the SocketRocket group into your app.
- Include SocketRocket as a subproject and use libSocketRocket

  If you do this, you must add -ObjC to your "other linker flags" option

- For OS X you will have to repackage make a .framework target.  I will take
  contributions. Message me if you are interested.


Depending on how you configure your project you may need to ``#import`` either
``<SocketRocket/SRWebSocket.h>`` or ``"SRWebSocket.h"``

Framework Dependencies
``````````````````````
Your .app must be linked against the following frameworks/dylibs

- libicucore.dylib
- CFNetwork.framework
- Security.framework
- Foundation.framework



按钮拖拽产生定义事件

https://www.cnblogs.com/foxting/p/SWIFT.html


node的server代码

"use strict";
process.title = 'node-chat';
var webSocketsServerPort = 3001;
var webSocketServer = require('websocket').server;
var http = require('http');
var history = [ ];
var clients = [ ];
var server = http.createServer(function(request, response) {
    // Not important for us. We're writing WebSocket server, not HTTP server
});
server.listen(webSocketsServerPort, function() {
    console.log((new Date()) + " Server is listening on port " + webSocketsServerPort);
});

var wsServer = new webSocketServer({
    httpServer: server
});

wsServer.on('request', function(request) {
    console.log((new Date()) + ' Connection from origin ' + request.origin + '.');
    var connection = request.accept(null, request.origin);
    var index = clients.push(connection) - 1;
    console.log((new Date()) + ' Connection accepted.');

    // send back chat history
    if (history.length > 0) {
        connection.sendUTF(JSON.stringify( { type: 'history', data: history} ));
    }

    // user sent some message
    connection.on('message', function(message) {
        //connection.sendUTF(JSON.stringify({ type:'color', data: userColor }));
		console.log("server receive:"+JSON.stringify(message));
        connection.sendUTF("单发 hello:"+message.utf8Data);
    });

    // user disconnected
    connection.on('close', function(connection) {
        console.log((new Date()) + " Peer "
                + connection.remoteAddress + " disconnected.");
    });

});


h5代码

<html>
<body>
<div id="output"></div>
<script>
function checkBrowser(){
	if (window.WebSocket){
		log("This browser supports WebSocket!");
	} else {
		log("This browser does not support WebSocket.");
	}
}
function setup(){
	//var wsServer = 'ws://13.115.181.153:3001';
	var wsServer = 'ws://localhost:3001';
	var ws = new WebSocket(wsServer);

	ws.onopen = function (e) {
		log("Connected to WebSocket server.",e);
		sendMessage("hello");
	} ;

	ws.onclose = function (e) {
		log("Disconnected",e);
	} ;

	ws.onmessage = function(e) {
		log("RECEIVED: " + e.data, e);
		ws.close();
	}

	ws.onerror = function (e) {
		log('Error occured: ' + e.data,e);
	} ;

	var sendMessage = function(msg){
		ws.send(msg);
		log("SEND : "+ msg);
	}
}

function log(s,e) {
	var output = document.getElementById("output");
	var p = document.createElement("p");
	p.style.wordWrap = "break-word";
	p.style.padding="10px";
	p.style.background="#eee";
	p.textContent = "LOG : "+s;
	output.appendChild(p);
	console.log("LOG : "+s, e);
}

checkBrowser();
setup();
</script>
</body>
</html>



ios代码
//
//  ViewController.m
//  secondim
//
//  Created by haoning on 2018/4/3.
//  Copyright © 2018年 haoning. All rights reserved.
//

#import "ViewController.h"
#import "SRWebSocket.h"

@interface ViewController () <SRWebSocketDelegate>

@end

@implementation ViewController {
    SRWebSocket *_webSocket;
    NSMutableArray *_messages;
    IBOutlet UIButton *thisbtn;
    IBOutlet UILabel *showme;
    IBOutlet UITextField *mytext;
}

- (IBAction)hitme:(id)sender {
    printf("hello hit me!!\n");
    NSString *message = @"aaa";
    message =  mytext.text;
    [_webSocket send:message];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    printf("haha begin--> \n");
    _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://localhost:3001"]]];
    
    _webSocket.delegate = self;
    
    [_webSocket open];
    showme.text = @"haha i am label";
    [NSThread sleepForTimeInterval:0.1f];
    printf("haha   open--> \n");
   
   
    
    
    //[_webSocket close];
    printf("haha   close--> \n");
    printf("haha   end--> \n");
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
   // NSString *string1 = @"我是甲一号";
    //NSLog(@"Received =------>>>>>>>>>>%s \n",@"我是甲一号");
    showme.text=message;
}

- (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
  
}

- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection {

}

- (void)preferredContentSizeDidChangeForChildContentContainer:(nonnull id<UIContentContainer>)container {
    
}



- (void)systemLayoutFittingSizeDidChangeForChildContentContainer:(nonnull id<UIContentContainer>)container {
    
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(nonnull id<UIViewControllerTransitionCoordinator>)coordinator {
    
}

- (void)willTransitionToTraitCollection:(nonnull UITraitCollection *)newCollection withTransitionCoordinator:(nonnull id<UIViewControllerTransitionCoordinator>)coordinator {
    
}

- (void)didUpdateFocusInContext:(nonnull UIFocusUpdateContext *)context withAnimationCoordinator:(nonnull UIFocusAnimationCoordinator *)coordinator {
    
}

- (void)setNeedsFocusUpdate {
    
}



- (void)updateFocusIfNeeded {
    
}

@end



呵呵哒的demo里面的代码
//
//  NTESSessionViewController.m
//  NIM
//
//  Created by amao on 8/11/15.
//  Copyright (c) 2015 Netease. All rights reserved.
//

#import "NTESSessionViewController.h"
@import MobileCoreServices;
@import AVFoundation;
#import "Reachability.h"
#import "UIActionSheet+NTESBlock.h"
#import "NTESCustomSysNotificationSender.h"
#import "NTESSessionConfig.h"
#import "NIMMediaItem.h"
#import "NTESSessionMsgConverter.h"
#import "NTESFileLocationHelper.h"
#import "NTESSessionMsgConverter.h"
#import "UIView+Toast.h"
#import "NTESSnapchatAttachment.h"
#import "NTESJanKenPonAttachment.h"
#import "NTESFileTransSelectViewController.h"
#import "NTESAudioChatViewController.h"
#import "NTESWhiteboardViewController.h"
#import "NTESVideoChatViewController.h"
#import "NTESChartletAttachment.h"
#import "NTESGalleryViewController.h"
#import "NTESVideoViewController.h"
#import "NTESFilePreViewController.h"
#import "NTESAudio2TextViewController.h"
#import "NSDictionary+NTESJson.h"
#import "NIMAdvancedTeamCardViewController.h"
#import "NTESSessionRemoteHistoryViewController.h"
#import "NIMNormalTeamCardViewController.h"
#import "UIView+NTES.h"
#import "NTESBundleSetting.h"
#import "NTESPersonalCardViewController.h"
#import "NTESSessionSnapchatContentView.h"
#import "NTESSessionLocalHistoryViewController.h"
#import "NIMContactSelectViewController.h"
#import "SVProgressHUD.h"
#import "NTESSessionCardViewController.h"
#import "NTESFPSLabel.h"
#import "UIAlertView+NTESBlock.h"
#import "NIMKit.h"
#import "NTESSessionUtil.h"
#import "NIMKitMediaFetcher.h"
#import "NIMKitLocationPoint.h"
#import "NIMLocationViewController.h"
#import "NIMKitInfoFetchOption.h"
#import "NTESSubscribeManager.h"
#import "NTESTeamMeetingViewController.h"
#import "NTESTeamMeetingCallerInfo.h"
#import "NIMInputAtCache.h"
#import "NTESRobotCardViewController.h"
#import "NTESRedPacketManager.h"
#import "NTESSessionRedPacketContentView.h"
#import "NTESSessionRedPacketTipContentView.h"
#import "NTESRedPacketAttachment.h"
#import "NTESRedPacketTipAttachment.h"
#import "NTESCellLayoutConfig.h"
#import "NTESTeamReceiptSendViewController.h"
#import "NTESTeamReceiptDetailViewController.h"
#import "SRWebSocket.h"

@interface NTESSessionViewController ()
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
NIMSystemNotificationManagerDelegate,
NIMMediaManagerDelegate,
NTESTimerHolderDelegate,
NIMContactSelectDelegate,
NIMEventSubscribeManagerDelegate,SRWebSocketDelegate>

@property (nonatomic,strong)    NTESCustomSysNotificationSender *notificaionSender;
@property (nonatomic,strong)    NTESSessionConfig       *sessionConfig;
@property (nonatomic,strong)    UIImagePickerController *imagePicker;
@property (nonatomic,strong)    NTESTimerHolder         *titleTimer;
@property (nonatomic,strong)    UIView *currentSingleSnapView;
@property (nonatomic,strong)    NTESFPSLabel *fpsLabel;
@property (nonatomic,strong)    NIMKitMediaFetcher *mediaFetcher;
@end



@implementation NTESSessionViewController{
    
    SRWebSocket *_webSocket;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://13.115.181.153:3001"]]];
    
    _webSocket.delegate = self;
    
    [_webSocket open];
    
    
    DDLogInfo(@"---->enter session, id = %@",self.session.sessionId);
    _notificaionSender  = [[NTESCustomSysNotificationSender alloc] init];
    [self setUpNav];
    BOOL disableCommandTyping = self.disableCommandTyping || (self.session.sessionType == NIMSessionTypeP2P &&[[NIMSDK sharedSDK].userManager isUserInBlackList:self.session.sessionId]);
    if (!disableCommandTyping) {
        _titleTimer = [[NTESTimerHolder alloc] init];
        [[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
    }

    if ([[NTESBundleSetting sharedConfig] showFps])
    {
        self.fpsLabel = [[NTESFPSLabel alloc] initWithFrame:CGRectZero];
        [self.view addSubview:self.fpsLabel];
        self.fpsLabel.right = self.view.width;
        self.fpsLabel.top   = self.tableView.top + self.tableView.contentInset.top;
    }
    
    if (self.session.sessionType == NIMSessionTypeP2P && !self.disableOnlineState)
    {
        //临时订阅这个人的在线状态 haohao
        [[NTESSubscribeManager sharedManager] subscribeTempUserOnlineState:self.session.sessionId];
        [[NIMSDK sharedSDK].subscribeManager addDelegate:self];
    }
    
    //删除最近会话列表中有人@你的标记
    [NTESSessionUtil removeRecentSessionAtMark:self.session];
    
}

- (void)dealloc
{
    printf("------dealloc---->\n");
    [[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
    if (self.session.sessionType == NIMSessionTypeP2P && !self.disableOnlineState)
    {
        [[NIMSDK sharedSDK].subscribeManager removeDelegate:self];
        [[NTESSubscribeManager sharedManager] unsubscribeTempUserOnlineState:self.session.sessionId];
    }
    [_fpsLabel invalidate];
}



- (void)viewDidLayoutSubviews{
    printf("------viewDidLayoutSubviews---->\n");
    [super viewDidLayoutSubviews];
    self.fpsLabel.right = self.view.width;
    self.fpsLabel.top   = self.tableView.top + self.tableView.contentInset.top;
}


- (void)viewWillDisappear:(BOOL)animated{
     printf("------viewWillDisappear---->\n");
    [super viewWillDisappear:animated];
    [[NIMSDK sharedSDK].mediaManager stopRecord];
    [[NIMSDK sharedSDK].mediaManager stopPlay];
}

- (id<NIMSessionConfig>)sessionConfig
{
     printf("------sessionConfig---->\n");
    if (_sessionConfig == nil) {
        printf("------sessionConfig-is-nil-->\n");
        _sessionConfig = [[NTESSessionConfig alloc] init];
        _sessionConfig.session = self.session;
    }
    return _sessionConfig;
}

#pragma mark - NIMEventSubscribeManagerDelegate
- (void)onRecvSubscribeEvents:(NSArray *)events
{
    printf("------onRecvSubscribeEvents---->\n");
    for (NIMSubscribeEvent *event in events) {
        if ([event.from isEqualToString:self.session.sessionId]) {
            [self refreshSessionSubTitle:[NTESSessionUtil onlineState:self.session.sessionId detail:YES]];
        }
    }
}
#pragma mark - NIMSystemNotificationManagerDelegate
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification
{
    printf("--->onReceiveCustomSystemNotification------------->\n");
    if (!notification.sendToOnlineUsersOnly) {
        return;
    }
    NSData *data = [[notification content] dataUsingEncoding:NSUTF8StringEncoding];
    if (data) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
                                                             options:0
                                                               error:nil];
        if ([dict jsonInteger:NTESNotifyID] == NTESCommandTyping && self.session.sessionType == NIMSessionTypeP2P && [notification.sender isEqualToString:self.session.sessionId])
        {
            [self refreshSessionTitle:@"正在输入..."];//haohao
            [_titleTimer startTimer:5
                           delegate:self
                            repeats:NO];
        }
    }
    
    
}

- (void)onNTESTimerFired:(NTESTimerHolder *)holder
{
    printf("--->onNTESTimerFired--->\n");
    [self refreshSessionTitle:self.sessionTitle];
}


- (NSString *)sessionTitle
{
    printf("--->sessionTitle--->\n");
    if ([self.session.sessionId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) {
        return  @"我的电脑";
    }
    return [super sessionTitle];
}

- (NSString *)sessionSubTitle
{
    printf("------sessionSubTitle---->\n");
    if (self.session.sessionType == NIMSessionTypeP2P && ![self.session.sessionId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) {
        return [NTESSessionUtil onlineState:self.session.sessionId detail:YES];
    }
    return @"";
}

- (void)onTextChanged:(id)sender
{
    printf("hello--->onTextChanged--->\n");
    [_notificaionSender sendTypingState:self.session];
}

- (void)onSelectChartlet:(NSString *)chartletId
                 catalog:(NSString *)catalogId
{
    printf("hello--->onSelectChartlet--->\n");
    NTESChartletAttachment *attachment = [[NTESChartletAttachment alloc] init];
    attachment.chartletId = chartletId;
    attachment.chartletCatalog = catalogId;
    [self sendMessage:[NTESSessionMsgConverter msgWithChartletAttachment:attachment]];
}


#pragma mark - 石头剪子布
- (void)onTapMediaItemJanKenPon:(NIMMediaItem *)item
{
    printf("hello--->onTapMediaItemJanKenPon--->\n");
    NTESJanKenPonAttachment *attachment = [[NTESJanKenPonAttachment alloc] init];
    attachment.value = arc4random() % 3 + 1;
    [self sendMessage:[NTESSessionMsgConverter msgWithJenKenPon:attachment]];
}

#pragma mark - 实时语音
- (void)onTapMediaItemAudioChat:(NIMMediaItem *)item
{
    printf("------onTapMediaItemAudioChat---->\n");
    if ([self checkRTSCondition]) {
        //由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
        NTESAudioChatViewController *vc = [[NTESAudioChatViewController alloc] initWithCallee:self.session.sessionId];
        CATransition *transition = [CATransition animation];
        transition.duration = 0.25;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
        transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromTop;
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        self.navigationController.navigationBarHidden = YES;
        [self.navigationController pushViewController:vc animated:NO];
    }
}

#pragma mark - 视频聊天
- (void)onTapMediaItemVideoChat:(NIMMediaItem *)item
{
    printf("------onTapMediaItemVideoChat---->\n");
    if ([self checkRTSCondition]) {
        //由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
        NTESVideoChatViewController *vc = [[NTESVideoChatViewController alloc] initWithCallee:self.session.sessionId];
        CATransition *transition = [CATransition animation];
        transition.duration = 0.25;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
        transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromTop;
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        self.navigationController.navigationBarHidden = YES;
        [self.navigationController pushViewController:vc animated:NO];
    }
}

#pragma mark - 群组会议
- (void)onTapMediaItemTeamMeeting:(NIMMediaItem *)item
{
    printf("------onTapMediaItemTeamMeeting---->\n");
    if ([self checkRTSCondition])
    {
        NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:self.session.sessionId];
        NSString *currentUserID = [[[NIMSDK sharedSDK] loginManager] currentAccount];
        NIMContactTeamMemberSelectConfig *config = [[NIMContactTeamMemberSelectConfig alloc] init];
        config.teamId = team.teamId;
        config.filterIds = @[currentUserID];
        config.needMutiSelected = YES;
        config.maxSelectMemberCount = 8;
        config.showSelectDetail = YES;
        NIMContactSelectViewController *vc = [[NIMContactSelectViewController alloc] initWithConfig:config];
        __weak typeof(self) weakSelf = self;
        vc.finshBlock = ^(NSArray * memeber){
            NSString *me = [NIMSDK sharedSDK].loginManager.currentAccount;
            NTESTeamMeetingCallerInfo *info = [[NTESTeamMeetingCallerInfo alloc] init];
            info.members = [@[me] arrayByAddingObjectsFromArray:memeber];
            info.teamId = team.teamId;
            NTESTeamMeetingViewController *vc = [[NTESTeamMeetingViewController alloc] initWithCallerInfo:info];
            [weakSelf presentViewController:vc animated:NO completion:nil];
        };;
        [vc show];
    }
}


#pragma mark - 文件传输
- (void)onTapMediaItemFileTrans:(NIMMediaItem *)item
{
    printf("------onTapMediaItemFileTrans---->\n");
    NTESFileTransSelectViewController *vc = [[NTESFileTransSelectViewController alloc]
                                             initWithNibName:nil bundle:nil];
    __weak typeof(self) wself = self;
    vc.completionBlock = ^void(id sender,NSString *ext){
        if ([sender isKindOfClass:[NSString class]]) {
            [wself sendMessage:[NTESSessionMsgConverter msgWithFilePath:sender]];
        }else if ([sender isKindOfClass:[NSData class]]){
            [wself sendMessage:[NTESSessionMsgConverter msgWithFileData:sender extension:ext]];
        }
    };
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 阅后即焚
- (void)onTapMediaItemSnapChat:(NIMMediaItem *)item
{
    printf("------onTapMediaItemSnapChat---->\n");
    UIActionSheet *sheet;
    BOOL isCamraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    if (isCamraAvailable) {
        sheet = [[UIActionSheet alloc] initWithTitle:@"请选择" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册中选取",@"拍照",nil];
    }else{
        sheet = [[UIActionSheet alloc] initWithTitle:@"请选择" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册中选取",nil];
    }
    __weak typeof(self) wself = self;
    [sheet showInView:self.view completionHandler:^(NSInteger index) {
        switch (index) {
            case 0:{
                //相册
                [wself.mediaFetcher fetchPhotoFromLibrary:^(NSArray *images, NSString *path, PHAssetMediaType type){
                    if (images.count) {
                        [wself sendSnapchatMessage:images.firstObject];
                    }
                    if (path) {
                        [wself sendSnapchatMessagePath:path];
                    }
                }];
                
            }
                break;
            case 1:{
                //相机
                [wself.mediaFetcher fetchMediaFromCamera:^(NSString *path, UIImage *image) {
                    if (image) {
                        [wself sendSnapchatMessage:image];
                    }
                }];
            }
                break;
            default:
                return;
        }
    }];
}

- (void)sendSnapchatMessagePath:(NSString *)path
{
    
    printf("---->sendSnapchatMessagePath--->\n");
    NTESSnapchatAttachment *attachment = [[NTESSnapchatAttachment alloc] init];
    [attachment setImageFilePath:path];
    [self sendMessage:[NTESSessionMsgConverter msgWithSnapchatAttachment:attachment]];
}

- (void)sendSnapchatMessage:(UIImage *)image
{
    printf("---->sendSnapchatMessage--->\n");
    NTESSnapchatAttachment *attachment = [[NTESSnapchatAttachment alloc] init];
    [attachment setImage:image];
    [self sendMessage:[NTESSessionMsgConverter msgWithSnapchatAttachment:attachment]];
}

#pragma mark - 白板
- (void)onTapMediaItemWhiteBoard:(NIMMediaItem *)item
{
    printf("------onTapMediaItemWhiteBoard---->\n");
    NTESWhiteboardViewController *vc = [[NTESWhiteboardViewController alloc] initWithSessionID:nil
                                                                                        peerID:self.session.sessionId
                                                                                         types:NIMRTSServiceReliableTransfer | NIMRTSServiceAudio
                                                                                          info:@"白板演示"];
    [self presentViewController:vc animated:NO completion:nil];
}



#pragma mark - 提示消息
- (void)onTapMediaItemTip:(NIMMediaItem *)item
{
    printf("------onTapMediaItemTip---->\n");
    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:nil message:@"输入提醒" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert showAlertWithCompletionHandler:^(NSInteger index) {
        switch (index) {
            case 1:{
                UITextField *textField = [alert textFieldAtIndex:0];
                NIMMessage *message = [NTESSessionMsgConverter msgWithTip:textField.text];
                [self sendMessage:message];

            }
                break;
            default:
                break;
        }
    }];
}

#pragma mark - 红包
- (void)onTapMediaItemRedPacket:(NIMMediaItem *)item
{
    printf("------onTapMediaItemRedPacket---->\n");
    [[NTESRedPacketManager sharedManager] sendRedPacket:self.session];
}

#pragma mark - 群已读回执
- (void)onTapMediaItemTeamReceipt:(NIMMediaItem *)item
{
    printf("------onTapMediaItemTeamReceipt---->\n");
    NTESTeamReceiptSendViewController *vc = [[NTESTeamReceiptSendViewController alloc] initWithSession:self.session];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - 消息发送时间截获
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error
{
    printf("sendMessage---->hello hit me!!\n");
   // NSString *message_temp = @"aaa";
    //message =  mytext.text;
   // [_webSocket send:message_temp];
    
    [_webSocket send:message.text];
    
    
//  printf("------->sendMessage--begin----->\n");
    NSLog(@"---NTESSessionViewController-->sendMessage----->>>>>>%@",message);
//  printf("------->sendMessage--end----->\n");
    if (error.code == NIMRemoteErrorCodeInBlackList)
    {
        //消息打上拉黑拒收标记,方便 UI 显示
        message.localExt = @{NTESMessageRefusedTag:@(true)};
        [[NIMSDK sharedSDK].conversationManager updateMessage:message forSession:self.session completion:nil];
        
        //插入一条 Tip 提示
        NIMMessage *tip = [NTESSessionMsgConverter msgWithTip:@"消息已发送,但对方拒收"];
        [[NIMSDK sharedSDK].conversationManager saveMessage:tip forSession:self.session completion:nil];
    }
    [super sendMessage:message didCompleteWithError:error];
}

#pragma mark - 录音事件
- (void)onRecordFailed:(NSError *)error
{
    printf("------onRecordFailed---->\n");
    [self.view makeToast:@"录音失败" duration:2 position:CSToastPositionCenter];
}

- (BOOL)recordFileCanBeSend:(NSString *)filepath
{
     printf("------recordFileCanBeSend---->\n");
    NSURL    *URL = [NSURL fileURLWithPath:filepath];
    AVURLAsset *urlAsset = [[AVURLAsset alloc]initWithURL:URL options:nil];
    CMTime time = urlAsset.duration;
    CGFloat mediaLength = CMTimeGetSeconds(time);
    return mediaLength > 2;
}

- (void)showRecordFileNotSendReason
{
    printf("------showRecordFileNotSendReason---->\n");
    [self.view makeToast:@"录音时间太短" duration:0.2f position:CSToastPositionCenter];
}

#pragma mark - Cell事件
- (BOOL)onTapCell:(NIMKitEvent *)event
{
    printf("----onTapCell----->\n");
    BOOL handled = [super onTapCell:event];
    NSString *eventName = event.eventName;
    if ([eventName isEqualToString:NIMKitEventNameTapContent])
    {
        NIMMessage *message = event.messageModel.message;
        NSDictionary *actions = [self cellActions];
        NSString *value = actions[@(message.messageType)];
        if (value) {
            SEL selector = NSSelectorFromString(value);
            if (selector && [self respondsToSelector:selector]) {
                SuppressPerformSelectorLeakWarning([self performSelector:selector withObject:message]);
                handled = YES;
            }
        }
    }
    else if([eventName isEqualToString:NIMKitEventNameTapLabelLink])
    {
        NSString *link = event.data;
        [self openSafari:link];
        handled = YES;
    }
    else if([eventName isEqualToString:NIMDemoEventNameOpenSnapPicture])
    {
        NIMCustomObject *object = event.messageModel.message.messageObject;
        NTESSnapchatAttachment *attachment = (NTESSnapchatAttachment *)object.attachment;
        if(attachment.isFired){
            return handled;
        }
        UIView *sender = event.data;
        self.currentSingleSnapView = [NTESGalleryViewController alertSingleSnapViewWithMessage:object.message baseView:sender];
        handled = YES;
    }
    else if([eventName isEqualToString:NIMDemoEventNameCloseSnapPicture])
    {
        //点击很快的时候可能会触发两次查看,所以这里不管有没有查看过 先强直销毁掉
        NIMCustomObject *object = event.messageModel.message.messageObject;
        UIView *senderView = event.data;
        [senderView dismissPresentedView:YES complete:nil];
        
        NTESSnapchatAttachment *attachment = (NTESSnapchatAttachment *)object.attachment;
        if(attachment.isFired){
            return handled;
        }
        attachment.isFired  = YES;
        NIMMessage *message = object.message;
        if ([NTESBundleSetting sharedConfig].autoRemoveSnapMessage) {
            [[NIMSDK sharedSDK].conversationManager deleteMessage:message];
            [self uiDeleteMessage:message];
        }else{
            [[NIMSDK sharedSDK].conversationManager updateMessage:message forSession:message.session completion:nil];
            [self uiUpdateMessage:message];
        }
        [[NSFileManager defaultManager] removeItemAtPath:attachment.filepath error:nil];
        self.currentSingleSnapView = nil;
        handled = YES;
    }
    else if([eventName isEqualToString:NIMKitEventNameTapRobotLink])
    {
        NSString *link = event.data;
        [self openSafari:link];
        handled = YES;
    }
    else if([eventName isEqualToString:NIMDemoEventNameOpenRedPacket])
    {
        NIMCustomObject *object = event.messageModel.message.messageObject;
        NTESRedPacketAttachment *attachment = (NTESRedPacketAttachment *)object.attachment;
        [[NTESRedPacketManager sharedManager] openRedPacket:attachment.redPacketId from:event.messageModel.message.from session:self.session];
        handled = YES;
    }
    else if([eventName isEqualToString:NTESShowRedPacketDetailEvent])
    {
        NIMCustomObject *object = event.messageModel.message.messageObject;
        NTESRedPacketTipAttachment *attachment = (NTESRedPacketTipAttachment *)object.attachment;
        [[NTESRedPacketManager sharedManager] showRedPacketDetail:attachment.packetId];
        handled = YES;
    }
    if (!handled) {
        NSAssert(0, @"invalid event");
    }
    return handled;
}

- (BOOL)onTapAvatar:(NIMMessage *)message{
     printf("------onTapAvatar---->\n");
    NSString *userId = [self messageSendSource:message];
    UIViewController *vc = nil;
    if ([[NIMSDK sharedSDK].robotManager isValidRobot:userId])
    {
        vc = [[NTESRobotCardViewController alloc] initWithUserId:userId];
    }
    else
    {
        vc = [[NTESPersonalCardViewController alloc] initWithUserId:userId];
    }
    
    [self.navigationController pushViewController:vc animated:YES];
    return YES;
}


- (BOOL)onLongPressAvatar:(NIMMessage *)message
{
    printf("------onLongPressAvatar---->\n");
    NSString *userId = [self messageSendSource:message];
    if (self.session.sessionType == NIMSessionTypeTeam && ![userId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount])
    {
        NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
        option.session = self.session;
        option.forbidaAlias = YES;
        
        NSString *nick = [[NIMKit sharedKit].provider infoByUser:userId option:option].showName;
        NSString *text = [NSString stringWithFormat:@"%@%@%@",NIMInputAtStartChar,nick,NIMInputAtEndChar];
        
        NIMInputAtItem *item = [[NIMInputAtItem alloc] init];
        item.uid  = userId;
        item.name = nick;
        [self.sessionInputView.atCache addAtItem:item];
        
        [self.sessionInputView.toolBar insertText:text];
    }
    return YES;
}

- (BOOL)onPressReadLabel:(NIMMessage *)message
{
    printf("------onPressReadLabel---->\n");
    if (self.session.sessionType == NIMSessionTypeTeam)
    {
        NTESTeamReceiptDetailViewController *vc = [[NTESTeamReceiptDetailViewController alloc] initWithMessage:message];
        [self.navigationController pushViewController:vc animated:YES];
    }
    return YES;
}


- (NSString *)messageSendSource:(NIMMessage *)message
{
    printf("------messageSendSource---->\n");
    NSString *from = nil;
    if (message.messageType == NIMMessageTypeRobot)
    {
        NIMRobotObject *object = (NIMRobotObject *)message.messageObject;
        if (object.isFromRobot)
        {
            from = object.robotId;
        }
    }
    if (!from)
    {
        from = message.from;
    }
    return from;
}


#pragma mark - Cell Actions
- (void)showImage:(NIMMessage *)message
{
    printf("------showImage---->\n");
    NIMImageObject *object = message.messageObject;
    NTESGalleryItem *item = [[NTESGalleryItem alloc] init];
    item.thumbPath      = [object thumbPath];
    item.imageURL       = [object url];
    item.name           = [object displayName];
    item.itemId         = [message messageId];
    item.size           = [object size];
    
    NIMSession *session = [self isMemberOfClass:[NTESSessionViewController class]]? self.session : nil;
    
    NTESGalleryViewController *vc = [[NTESGalleryViewController alloc] initWithItem:item session:session];
    [self.navigationController pushViewController:vc animated:YES];
    if(![[NSFileManager defaultManager] fileExistsAtPath:object.thumbPath]){
        //如果缩略图下跪了,点进看大图的时候再去下一把缩略图
        __weak typeof(self) wself = self;
        [[NIMSDK sharedSDK].resourceManager download:object.thumbUrl filepath:object.thumbPath progress:nil completion:^(NSError *error) {
            if (!error) {
                [wself uiUpdateMessage:message];
            }
        }];
    }
}

- (void)showVideo:(NIMMessage *)message
{
    printf("------showVideo---->\n");
    NIMVideoObject *object = message.messageObject;
    NIMSession *session = [self isMemberOfClass:[NTESSessionViewController class]]? self.session : nil;
    
    NTESVideoViewItem *item = [[NTESVideoViewItem alloc] init];
    item.path = object.path;
    item.url  = object.url;
    item.session = session;
    item.itemId  = object.message.messageId;
    
    NTESVideoViewController *playerViewController = [[NTESVideoViewController alloc] initWithVideoViewItem:item];
    [self.navigationController pushViewController:playerViewController animated:YES];
    if(![[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
        //如果封面图下跪了,点进视频的时候再去下一把封面图
        __weak typeof(self) wself = self;
        [[NIMSDK sharedSDK].resourceManager download:object.coverUrl filepath:object.coverPath progress:nil completion:^(NSError *error) {
            if (!error) {
                [wself uiUpdateMessage:message];
            }
        }];
    }
}

- (void)showLocation:(NIMMessage *)message
{
    printf("------showLocation---->\n");
    NIMLocationObject *object = message.messageObject;
    NIMKitLocationPoint *locationPoint = [[NIMKitLocationPoint alloc] initWithLocationObject:object];
    NIMLocationViewController *vc = [[NIMLocationViewController alloc] initWithLocationPoint:locationPoint];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)showFile:(NIMMessage *)message
{
    printf("------showFile---->\n");
    NIMFileObject *object = message.messageObject;
    NTESFilePreViewController *vc = [[NTESFilePreViewController alloc] initWithFileObject:object];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)showCustom:(NIMMessage *)message
{
    printf("------showCustom-|haohao|--->\n");
   //普通的自定义消息点击事件可以在这里做哦~
}

- (void)openSafari:(NSString *)link
{
    printf("------openSafari---->\n");
    NSURLComponents *components = [[NSURLComponents alloc] initWithString:link];
    if (components)
    {
        if (!components.scheme)
        {
            //默认添加 http
            components.scheme = @"http";
        }
        [[UIApplication sharedApplication] openURL:[components URL]];
    }
}


#pragma mark - 导航按钮
- (void)enterPersonInfoCard:(id)sender{
    printf("------enterPersonInfoCard---->\n");
    NTESSessionCardViewController *vc = [[NTESSessionCardViewController alloc] initWithSession:self.session];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)enterRobotInfoCard:(id)sender{
    printf("------enterRobotInfoCard---->\n");
    NTESRobotCardViewController *vc = [[NTESRobotCardViewController alloc] initWithUserId:self.session.sessionId];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)enterHistory:(id)sender{
     printf("------enterHistory---->\n");
    
    [self.view endEditing:YES];
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择操作" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"云消息记录",@"搜索本地消息记录",@"清空本地聊天记录", nil];
    [sheet showInView:self.view completionHandler:^(NSInteger index) {
        switch (index) {
            case 0:{ //查看云端消息
                NTESSessionRemoteHistoryViewController *vc = [[NTESSessionRemoteHistoryViewController alloc] initWithSession:self.session];
                [self.navigationController pushViewController:vc animated:YES];
                break;
            }
            case 1:{ //搜索本地消息
                NTESSessionLocalHistoryViewController *vc = [[NTESSessionLocalHistoryViewController alloc] initWithSession:self.session];
                [self.navigationController pushViewController:vc animated:YES];
                break;
            }
            case 2:{ //清空聊天记录
                UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"确定清空聊天记录?" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
                __weak UIActionSheet *wSheet;
                [sheet showInView:self.view completionHandler:^(NSInteger index) {
                    if (index == wSheet.destructiveButtonIndex) {
                        BOOL removeRecentSession = [NTESBundleSetting sharedConfig].removeSessionWhenDeleteMessages;
                        BOOL removeTable = [NTESBundleSetting sharedConfig].dropTableWhenDeleteMessages;
                        NIMDeleteMessagesOption *option = [[NIMDeleteMessagesOption alloc] init];
                        option.removeSession = removeRecentSession;
                        option.removeTable = removeTable;
                        [[NIMSDK sharedSDK].conversationManager deleteAllmessagesInSession:self.session
                                                                                    option:option];
                    }
                }];
                break;
            }
            default:
                break;
        }
    }];
}

- (void)enterTeamCard:(id)sender{
    printf("------enterTeamCard---->\n");
    NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:self.session.sessionId];
    UIViewController *vc;
    if (team.type == NIMTeamTypeNormal) {
        vc = [[NIMNormalTeamCardViewController alloc] initWithTeam:team];
    }else if(team.type == NIMTeamTypeAdvanced){
        vc = [[NIMAdvancedTeamCardViewController alloc] initWithTeam:team];
    }
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 菜单
- (NSArray *)menusItems:(NIMMessage *)message
{
     printf("------menusItems---->\n");
    NSMutableArray *items = [NSMutableArray array];
    NSArray *defaultItems = [super menusItems:message];
    if (defaultItems) {
        [items addObjectsFromArray:defaultItems];
    }
    
    if ([NTESSessionUtil canMessageBeForwarded:message]) {
        [items addObject:[[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(forwardMessage:)]];
    }
    
    if ([NTESSessionUtil canMessageBeRevoked:message]) {
        [items addObject:[[UIMenuItem alloc] initWithTitle:@"撤回" action:@selector(revokeMessage:)]];
    }
    
    if (message.messageType == NIMMessageTypeAudio) {
        [items addObject:[[UIMenuItem alloc] initWithTitle:@"转文字" action:@selector(audio2Text:)]];
    }
    
    return items;
    
}

- (void)audio2Text:(id)sender
{//haohao
    printf("------audio2Text------>\n");
    NIMMessage *message = [self messageForMenu];
    __weak typeof(self) wself = self;
    NTESAudio2TextViewController *vc = [[NTESAudio2TextViewController alloc] initWithMessage:message];
    vc.completeHandler = ^(void){
        [wself uiUpdateMessage:message];
    };
    [self presentViewController:vc
                       animated:YES
                     completion:nil];
}


- (void)forwardMessage:(id)sender
{
    printf("---->forwardMessage---->\n");
    NIMMessage *message = [self messageForMenu];
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择会话类型" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"个人",@"群组", nil];
    __weak typeof(self) weakSelf = self;
    message.setting.teamReceiptEnabled = NO;
    [sheet showInView:self.view completionHandler:^(NSInteger index) {
        switch (index) {
            case 0:{
                NIMContactFriendSelectConfig *config = [[NIMContactFriendSelectConfig alloc] init];
                config.needMutiSelected = NO;
                NIMContactSelectViewController *vc = [[NIMContactSelectViewController alloc] initWithConfig:config];
                vc.finshBlock = ^(NSArray *array){
                    NSString *userId = array.firstObject;
                    NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
                    [weakSelf forwardMessage:message toSession:session];
                };
                [vc show];
            }
                break;
            case 1:{
                NIMContactTeamSelectConfig *config = [[NIMContactTeamSelectConfig alloc] init];
                NIMContactSelectViewController *vc = [[NIMContactSelectViewController alloc] initWithConfig:config];
                vc.finshBlock = ^(NSArray *array){
                    NSString *teamId = array.firstObject;
                    NIMSession *session = [NIMSession session:teamId type:NIMSessionTypeTeam];
                    [weakSelf forwardMessage:message toSession:session];
                };
                [vc show];
            }
                break;
            case 2:
                break;
            default:
                break;
        }
    }];
}


- (void)revokeMessage:(id)sender
{
    printf("---------revokeMessage---->\n");
    NIMMessage *message = [self messageForMenu];
    __weak typeof(self) weakSelf = self;
    [[NIMSDK sharedSDK].chatManager revokeMessage:message completion:^(NSError * _Nullable error) {
        if (error) {
            if (error.code == NIMRemoteErrorCodeDomainExpireOld) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"发送时间超过2分钟的消息,不能被撤回" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
            }else{
                DDLogError(@"revoke message eror code %zd",error.code);
                [weakSelf.view makeToast:@"消息撤回失败,请重试" duration:2.0 position:CSToastPositionCenter];
            }
        }
        else
        {
            NIMMessageModel *model = [self uiDeleteMessage:message];
            NIMMessage *tip = [NTESSessionMsgConverter msgWithTip:[NTESSessionUtil tipOnMessageRevoked:nil]];
            tip.timestamp = model.messageTime;
            [self uiInsertMessages:@[tip]];
            
            tip.timestamp = message.timestamp;
            // saveMessage 方法执行成功后会触发 onRecvMessages: 回调,但是这个回调上来的 NIMMessage 时间为服务器时间,和界面上的时间有一定出入,所以要提前先在界面上插入一个和被删消息的界面时间相符的 Tip, 当触发 onRecvMessages: 回调时,组件判断这条消息已经被插入过了,就会忽略掉。
            [[NIMSDK sharedSDK].conversationManager saveMessage:tip forSession:message.session completion:nil];
        }
    }];
}

 - (void)forwardMessage:(NIMMessage *)message toSession:(NIMSession *)session
{
    printf("---->forwardMessage--->\n");
    NSString *name;
    if (session.sessionType == NIMSessionTypeP2P)
    {
        NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
        option.session = session;
        name = [[NIMKit sharedKit] infoByUser:session.sessionId option:option].showName;
    }
    else
    {
        name = [[NIMKit sharedKit] infoByTeam:session.sessionId option:nil].showName;
    }
    NSString *tip = [NSString stringWithFormat:@"确认转发给 %@ ?",name];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"确认转发" message:tip delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    
    __weak typeof(self) weakSelf = self;
    [alert showAlertWithCompletionHandler:^(NSInteger index) {
        if(index == 1)
        {
            if (message.messageType == NIMMessageTypeRobot)
            {
                NIMMessage *forwardMessage = [NTESSessionMsgConverter msgWithText:message.text];
                [[NIMSDK sharedSDK].chatManager sendMessage:forwardMessage toSession:session error:nil];
            }
            else
            {
                [[NIMSDK sharedSDK].chatManager forwardMessage:message toSession:session error:nil];
            }
            [weakSelf.view makeToast:@"已发送" duration:2.0 position:CSToastPositionCenter];
        }
    }];
}

#pragma mark - 辅助方法
- (void)sendImageMessagePath:(NSString *)path
{

     printf("------sendImageMessagePath---->\n");
    [self sendSnapchatMessagePath:path];
}


- (BOOL)checkRTSCondition
{
    printf("------checkRTSCondition---->\n");
    BOOL result = YES;
    
    if (![[Reachability reachabilityForInternetConnection] isReachable])
    {
        [self.view makeToast:@"请检查网络" duration:2.0 position:CSToastPositionCenter];
        result = NO;
    }
    NSString *currentAccount = [[NIMSDK sharedSDK].loginManager currentAccount];
    if (self.session.sessionType == NIMSessionTypeP2P && [currentAccount isEqualToString:self.session.sessionId])
    {
        [self.view makeToast:@"不能和自己通话哦" duration:2.0 position:CSToastPositionCenter];
        result = NO;
    }
    if (self.session.sessionType == NIMSessionTypeTeam)
    {
        NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:self.session.sessionId];
        NSInteger memberNumber = team.memberNumber;
        if (memberNumber < 2)
        {
            [self.view makeToast:@"无法发起,群人数少于2人" duration:2.0 position:CSToastPositionCenter];
            result = NO;
        }
    }
    return result;
}

- (NSDictionary *)cellActions
{
    printf("------cellActions---->\n");
    static NSDictionary *actions = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        actions = @{@(NIMMessageTypeImage) :    @"showImage:",
                    @(NIMMessageTypeVideo) :    @"showVideo:",
                    @(NIMMessageTypeLocation) : @"showLocation:",
                    @(NIMMessageTypeFile)  :    @"showFile:",
                    @(NIMMessageTypeCustom):    @"showCustom:"};
    });
    return actions;
}

- (NIMKitMediaFetcher *)mediaFetcher
{
    printf("------mediaFetcher---->\n");
    if (!_mediaFetcher) {
        _mediaFetcher = [[NIMKitMediaFetcher alloc] init];
        _mediaFetcher.limit = 1;
        _mediaFetcher.mediaTypes = @[(NSString *)kUTTypeImage];;;
    }
    return _mediaFetcher;
}

- (void)setUpNav{
    printf("------setUpNav---->\n");
    UIButton *enterTeamCard = [UIButton buttonWithType:UIButtonTypeCustom];
    [enterTeamCard addTarget:self action:@selector(enterTeamCard:) forControlEvents:UIControlEventTouchUpInside];
    [enterTeamCard setImage:[UIImage imageNamed:@"icon_session_info_normal"] forState:UIControlStateNormal];
    [enterTeamCard setImage:[UIImage imageNamed:@"icon_session_info_pressed"] forState:UIControlStateHighlighted];
    [enterTeamCard sizeToFit];
    UIBarButtonItem *enterTeamCardItem = [[UIBarButtonItem alloc] initWithCustomView:enterTeamCard];
    
    UIButton *infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [infoBtn addTarget:self action:@selector(enterPersonInfoCard:) forControlEvents:UIControlEventTouchUpInside];
    [infoBtn setImage:[UIImage imageNamed:@"icon_session_info_normal"] forState:UIControlStateNormal];
    [infoBtn setImage:[UIImage imageNamed:@"icon_session_info_pressed"] forState:UIControlStateHighlighted];
    [infoBtn sizeToFit];
    UIBarButtonItem *enterUInfoItem = [[UIBarButtonItem alloc] initWithCustomView:infoBtn];
    
    UIButton *historyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [historyBtn addTarget:self action:@selector(enterHistory:) forControlEvents:UIControlEventTouchUpInside];
    [historyBtn setImage:[UIImage imageNamed:@"icon_history_normal"] forState:UIControlStateNormal];
    [historyBtn setImage:[UIImage imageNamed:@"icon_history_pressed"] forState:UIControlStateHighlighted];
    [historyBtn sizeToFit];
    UIBarButtonItem *historyButtonItem = [[UIBarButtonItem alloc] initWithCustomView:historyBtn];
    
    
    UIButton *robotInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [robotInfoBtn addTarget:self action:@selector(enterRobotInfoCard:) forControlEvents:UIControlEventTouchUpInside];
    [robotInfoBtn setImage:[UIImage imageNamed:@"icon_robot_card_normal"] forState:UIControlStateNormal];
    [robotInfoBtn setImage:[UIImage imageNamed:@"icon_robot_card_pressed"] forState:UIControlStateHighlighted];
    [robotInfoBtn sizeToFit];
    UIBarButtonItem *robotInfoButtonItem = [[UIBarButtonItem alloc] initWithCustomView:robotInfoBtn];

    
    if (self.session.sessionType == NIMSessionTypeTeam)
    {
        self.navigationItem.rightBarButtonItems  = @[enterTeamCardItem,historyButtonItem];
    }
    else if(self.session.sessionType == NIMSessionTypeP2P)
    {
        if ([self.session.sessionId isEqualToString:[[NIMSDK sharedSDK].loginManager currentAccount]])
        {
            self.navigationItem.rightBarButtonItems = @[historyButtonItem];
        }
        else if([[NIMSDK sharedSDK].robotManager isValidRobot:self.session.sessionId])
        {
            self.navigationItem.rightBarButtonItems = @[historyButtonItem,robotInfoButtonItem];
        }
        else
        {
            self.navigationItem.rightBarButtonItems = @[enterUInfoItem,historyButtonItem];
        }
    }
}

- (BOOL)shouldAutorotate{
    printf("------shouldAutorotate---->\n");
    return !self.currentSingleSnapView;
}

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message_old {
    NSLog(@"Received --haha---->>>>>>>>>>%@ \n",message_old);
    printf("---->onRecvMessages--->\n");//haohao
  //  if ([self shouldAddListenerForNewMsg])
  //  {
        NIMMessage *message = [[NIMMessage alloc] init];
       // [message setMessageExt:@"7b468318-4c8a-47c6-ac09-81c96bf73324"];
       // [message setText:@"可以吧,从新的协议来的"];
        [message setText:message_old];
        NSArray *messages_new =[[NSArray alloc] initWithObjects:message, nil];

        NSLog(@"array:%@",messages_new.debugDescription);//haohao
        NSLog(@"one:%@",[messages_new objectAtIndex:0]);//haohao
        [self uiAddMessages:messages_new];
        //[super.interactor markRead];
  //  }
    
}

- (void)didFetchMessageData {
    
}

- (void)didPullUpMessageData {
    
}

- (void)didRefreshMessageData {
    
}

- (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
    
}

- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection {
    
}

- (void)preferredContentSizeDidChangeForChildContentContainer:(nonnull id<UIContentContainer>)container {
    
}



- (void)systemLayoutFittingSizeDidChangeForChildContentContainer:(nonnull id<UIContentContainer>)container {
    
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(nonnull id<UIViewControllerTransitionCoordinator>)coordinator {
    
}

- (void)willTransitionToTraitCollection:(nonnull UITraitCollection *)newCollection withTransitionCoordinator:(nonnull id<UIViewControllerTransitionCoordinator>)coordinator {
    
}

- (void)didUpdateFocusInContext:(nonnull UIFocusUpdateContext *)context withAnimationCoordinator:(nonnull UIFocusAnimationCoordinator *)coordinator {
    
}

- (void)setNeedsFocusUpdate {
    
}



- (void)updateFocusIfNeeded {
    
}

@end




效果
  • 大小: 97.3 KB
  • 大小: 177.5 KB
  • 大小: 255.7 KB
分享到:
评论

相关推荐

    SocketRocket的简易使用

    如果你选择Carthage,只需在Cartfile中添加`github "facebook/SocketRocket"`,并运行`carthage update`。 2. **创建WebSocket连接** 首先,你需要创建一个`SRWebSocket`实例,并指定WebSocket的URL。例如: ```...

    Facebook 网站架构总结

    Facebook作为一个全球知名的社交网络平台,其背后的技术架构是支撑亿级用户流畅互动的关键。Facebook的网站架构设计体现了模块化、整合化和清晰化的理念,旨在实现简单、高效的系统运作。以下是对Facebook架构的深入...

    预测facebook签到位置

    Facebook签到位置预测是一个涉及大数据分析、地理位置服务和社交网络行为学的复杂主题。在这个问题中,我们关注的是如何利用用户在Facebook上分享的签到信息来预测他们可能的未来签到位置。以下是对这个话题的详细...

    facebook api和facebook_jar包

    Facebook API和Facebook_JAR包是开发者用来与Facebook平台进行交互的重要工具,它们使得开发者能够创建应用程序,集成到Facebook生态系统中,实现数据交换、用户登录验证、发布内容等功能。Facebook API通常指的是...

    Facebook-Android-sdk-4.8.2

    Facebook Android SDK 4.8.2 是Facebook提供的一款用于帮助Android开发者在其应用中集成Facebook功能的开发工具包。这个版本的SDK包含了实现Facebook登录、分享、邀请、广告以及分析等功能所需的库和资源。通过使用...

    Facebook菜鸟到老鸟全系列运营玩法+Facebook专业广告投放全系列课程-视频教程网盘链接提取码下载.txt

    Facebook广告投放累计超过200万美元的经验数据分析以及总结,快速理解专业广告投放的重点,学完以后加以实操的练习很快就可以成为专业级的运营人才。 1、Facebook专业广告投放全系列课程(新) 2、Facebook菜鸟到...

    facebook分享

    在IT行业中,Facebook分享是一项常见的功能,特别是在移动应用和网页开发中。Facebook分享允许用户将内容,如文本、图片或链接,快速便捷地发布到他们的Facebook时间线,从而扩大信息的传播范围。在这个"facebook...

    Facebook登录分享发布信息程序

    总结来说,这个"Facebook登录分享发布信息程序"是利用C#的面向对象特性、Facebook的.NET SDK和Webview组件,实现了用户无感知的登录体验,以及方便的信息分享功能。开发者需要掌握C#编程、OAuth认证流程、Facebook ...

    web版facebook登录

    总结,Web版Facebook登录结合OAuth 2.0授权和Facebook Graph API,为用户提供便捷的登录体验。开发者在实施时需关注安全性和用户隐私,确保应用符合最佳实践。通过深入理解这些概念和技术,可以有效地集成Facebook...

    Unity Facebook API 官方 Demo 完整工程 代码

    Unity Facebook API 官方 Demo 是一个为游戏开发者提供的完整工程,它展示了如何在Unity引擎中集成Facebook的功能,以便实现用户登录、得分分享、排行榜展示以及头像获取等社交互动功能。这个Demo项目名为...

    facebook 的登录和统计的依赖工程

    在IT行业中,Facebook的登录和统计功能是许多开发者在构建应用程序时经常使用的工具。Facebook提供了SDK(Software Development Kit)来简化这些过程,使得开发者能够轻松地整合Facebook的登录系统和数据分析服务。...

    facebook-android-sdk-4.18.0.zip

    Facebook Android SDK 4.18.0 是一个用于在Android应用程序中集成Facebook功能的开发工具包。这个SDK允许开发者轻松地实现用户登录、分享、广告、分析和其他Facebook服务。2017年发布的这个版本是当时最新的,为...

    接入facebook登录获取apk秘钥散列

    接入Facebook登录功能是Android应用开发中的常见需求,它允许用户使用他们的Facebook账号快速登录到你的应用,提升用户体验。而为了实现这一功能,开发者需要获取到应用的APK秘钥散列(Key Hash),这是一个用于验证...

    wordpress WooCommerce Facebook 多像素插件

    **WordPress WooCommerce Facebook 多像素插件** 在电子商务领域,数据追踪和分析对于优化营销策略、提高广告效果至关重要。WordPress 的 WooCommerce 平台是许多在线商店的首选,而 Facebook Pixel 则是广告主用来...

    Facebook免费WiFi

    #### 四、总结 Facebook WiFi项目不仅解决了传统Wi-Fi网络接入过程中存在的诸多问题,如密码繁琐、难以管理等,而且还为企业提供了有效的宣传手段。对于用户而言,Facebook WiFi提供了一种便捷的免费上网方式;对于...

    打造Facebook:亲历Facebook爆发的5年

    这本书的书名——《打造Facebook:亲历Facebook爆发的5年》很嚣张,谁有资格可以说这句话呢,当然,扎克伯格最有资格,但他不会亲自来告诉你,至少从目前的情况来看,近几年都不大可能。而且,这不是一个人的公司。...

    vue使用facebook twitter分享示例

    facebook 分享文档 twitter 分享文档 vue 使用 facebook 使用分享 找到index.html 添加一下代码 &lt;!-- facebook 分享 --&gt; &lt;div id=fb-root&gt;&lt;/div&gt; [removed](function (d, s, id) { var js, fjs = d....

    FaceBook插件开发入门教程

    "FaceBook插件开发入门教程" 本文将从Facebook插件开发的角度,讲解如何创建一个简单的Facebook插件,并介绍Facebook插件开发的基本概念和流程。 一、Facebook插件开发简介 Facebook插件开发是指在Facebook平台上...

    Facebook的成功秘诀是什么

    #### 总结与展望 Facebook之所以能够在全球范围内取得巨大成功,关键在于其不断创新和适应市场需求的能力。从最初的校园社交平台,到后来的开放平台战略,再到近年来对于人工智能、虚拟现实等前沿技术的应用探索,...

Global site tag (gtag.js) - Google Analytics