IOS 即时通讯激活选择图片

#import 
// 定义一个协议
@class bingeInputView;
@protocol bingeInputView 
@optional
-(void)binge_inputView:(bingeInputView *)inputView moreBtnClickWith:(NSInteger)moreStyle;

@end

@interface bingeInputView : UIView

+(instancetype) binge_inputView;

@property (weak, nonatomic) IBOutlet UITextField *textField;

// 代理
@property(nonatomic,weak)id delegate;
@end
#import "bingeInputView.h"

@implementation bingeInputView

// 4.
+(instancetype)binge_inputView {
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}

// 语音
- (IBAction)changeInputStyle:(id)sender {
}
// 表情
- (IBAction)empressOnClick:(id)sender {
}
// ➕更多
- (IBAction)moreBtnClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(binge_inputView:moreBtnClickWith:)]) {
        [self.delegate binge_inputView:self moreBtnClickWith:0];
    }
}
#import "bingeChatViewController.h"
#import "bingeInputView.h"
#import "bingeChatTableViewCell.h"


#pragma mark - InputViewDelegate
-(void)binge_inputView:(bingeInputView *)inputView moreBtnClickWith:(NSInteger)moreStyle {
    // 先直接做图片选择
    UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    [self presentViewController:ipc animated:YES completion:nil];
}

#pragma mark - UINavigationControllerDelegate, UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:nil];
    
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    
    // 构造图片消息并发送
    EMImageMessageBody *body = [[EMImageMessageBody alloc]initWithChatObject:[[EMChatImage alloc]initWithUIImage:image displayName:@"展示的图片名"]];
    EMMessage *emsg = [[EMMessage alloc]initWithReceiver:self.buddy.username bodies:@[body]];
    __weak typeof(self) weakSelf = self;
    [[EaseMob sharedInstance].chatManager asyncSendMessage:emsg
                                                 progress:self
                                                  prepare:^(EMMessage *message, EMError *error) {
                                                      //
                                                  }
                                                  onQueue:nil
                                               completion:^(EMMessage *message, EMError *error) {
                                                   // 发送成功
//                                                   [self binge_reloadChatMsgs];
                                                   if (!error) {                                                       [weakSelf binge_reloadChatMsgs];
                                                   }
                                               }
                                                   onQueue:nil];
}

#pragma mark - IEMChatProgressDelegate 
-(void)setProgress:(float)progress {
    NSLog(@"%s,line = %d",__FUNCTION__,__LINE__);
}


#warning : [发送照片发送错误] -> [原因:没有实现方法]'-[bingeChatViewController setProgress:forMessage:forMessageBody:]: unrecognized selector sent to instance 0x7fa73d885440'

#warning : [解决方法] '-(void)setProgress:(float)progress forMessage:(EMMessage *)message forMessageBody:(id)messageBody'

-(void)setProgress:(float)progress forMessage:(EMMessage *)message forMessageBody:(id)messageBody {
    
    NSLog(@"%s,line = %d",__FUNCTION__,__LINE__);
}

你可能感兴趣的:(IOS 即时通讯激活选择图片)