IOS 即时通讯激活选择图片
2016-11-19 本文已影响0人
许威彬
#import <UIKit/UIKit.h>
// 定义一个协议
@class bingeInputView;
@protocol bingeInputView <NSObject>
@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<bingeInputView> 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<NSString *,id> *)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<IEMMessageBody>)messageBody'
-(void)setProgress:(float)progress forMessage:(EMMessage *)message forMessageBody:(id<IEMMessageBody>)messageBody {
NSLog(@"%s,line = %d",__FUNCTION__,__LINE__);
}