问题描述
[[EaseMob sharedInstance].chatManager insertMessagesToDB:array1];array是一个字典数组[{ id = 2121, filename = , status = 1, msg_id = 82839550610637252, msg_type = txt, type = chatmessage, timestamp = 1436852385910, url = , to_user = 81364249049301408, secret = , lat = 0, chat_type = groupchat, ext = null, lng = 0, addr = , msg = 红, length = 0, from_user = 19},{ id = 2120, filename = , status = 1, msg_id = 82839536849125828, msg_type = txt, type = chatmessage, timestamp = 1436852382701, url = , to_user = 81364249049301408, secret = , lat = 0, chat_type = groupchat, ext = null, lng = 0, addr = , msg = 他用, length = 0, from_user = 19},错误原因 -[__NSCFDictionary conversationChatter]: unrecognized selector sent to instance 0x10af59802015-07-27 15:00:12.525 breezeTourism[40993:1322549] NSScanner: nil string argument2015-07-27 15:00:12.525 breezeTourism[40993:1322549] NSScanner: nil string argument
解决方案
消息数据要包成EMMessage对象,然后才能插入到db的。
解决方案二:
怎么包装成EMMessage,是把我的字典数组转成模型吗,转成这个模型么,MessageModel *model?
解决方案三:
http://www.easemob.com/docs/io ... alloc
解决方案四:
我也是要这样写么,假如我保全上面的字典,有文字,图片,语音,视频等- (void)loadMessage{ NSDictionary *imageDic = @{EMMessageBodyAttrKeySecret:@"fmIgiuSuEeSdyLffbqYspd3oOH6uMSGkXaOvZUF9ayy5b26c", EMMessageBodyAttrKeySize:@{EMMessageBodyAttrKeySizeWidth:@laznrbfe,EMMessageBodyAttrKeySizeHeight:@1136}, EMMessageBodyAttrKeyFileName:@"image.jpg", EMMessageBodyAttrKeyType:EMMessageBodyAttrTypeImag, EMMessageBodyAttrKeyUrl:@"https://a1.easemob.com/easemob ... ot%3B, EMMessageBodyAttrKeyFileLength:@178212}; EMImageMessageBody *imageBody = [EMImageMessageBody imageMessageBodyFromBodyDict:imageDic forChatter:_chatter]; EMMessage *image = [[EMMessage alloc] initMessageWithID:@"50152415936119390" sender:_chatter receiver:@"my_test4" bodies:@[imageBody]]; image.timestamp = ([[NSDate date] timeIntervalSince1970] - 10) * 1000; image.isReadAcked = YES; image.deliveryState = eMessageDeliveryState_Delivered; image.isRead = YES; image.isGroup = self.isChatGroup; image.conversationChatter = @"my_test5"; NSDictionary *voiceDic = @{EMMessageBodyAttrKeySecret:@"ZTKmSuSxEeS2upsPo9JVK-E7e7W_Ieu6g55uSbYCQikqSmh1", EMMessageBodyAttrKeyFileName:@"audio chat", EMMessageBodyAttrKeyDuration:@自由的天天天, EMMessageBodyAttrKeyType:EMMessageBodyAttrTypeAudio, EMMessageBodyAttrKeyUrl:@"https://a1.easemob.com/easemob ... ot%3B, EMMessageBodyAttrKeyFileLength:@8870}; EMVoiceMessageBody *voiceBody = [EMVoiceMessageBody voiceMessageBodyFromBodyDict:voiceDic forChatter:_chatter]; EMMessage *voice = [[EMMessage alloc] initMessageWithID:@"50152415936119490" sender:_chatter receiver:@"my_test4" bodies:@[voiceBody]]; voice.timestamp = ([[NSDate date] timeIntervalSince1970] - 5) * 1000; voice.isReadAcked = YES; voice.deliveryState = eMessageDeliveryState_Delivered; voice.isRead = YES; voice.isGroup = _isChatGroup; voice.conversationChatter = @"my_test5"; NSDictionary *videoDic = @{EMMessageBodyAttrKeySecret:@"ANfQauSzEeSWceXUdNLCzOoCWyafJ0jg5AticaEKlEVCeqD2", EMMessageBodyAttrKeyDuration:@12, EMMessageBodyAttrKeyThumbSecret:@"AHShyuSzEeS9Eo2-FC-hEqTv7L96P5LNxUCo2zGrbZfu9FWz", EMMessageBodyAttrKeySize:@{EMMessageBodyAttrKeySizeWidth:@阿密特,EMMessageBodyAttrKeySizeHeight:@90}, EMMessageBodyAttrKeyThumb:@"https://a1.easemob.com/easemob ... ot%3B, EMMessageBodyAttrKeyFileName:@"video.mp4", EMMessageBodyAttrKeyType:@"video", EMMessageBodyAttrKeyFileLength:@1235670, EMMessageBodyAttrKeyUrl:@"https://a1.easemob.com/easemob ... ot%3B}; EMVideoMessageBody *videoBody = [EMVideoMessageBody videoMessageBodyFromBodyDict:videoDic forChatter:_chatter]; EMMessage *video = [[EMMessage alloc] initMessageWithID:@"50152415936119590" sender:_chatter receiver:@"my_test4" bodies:@[videoBody]]; video.timestamp = ([[NSDate date] timeIntervalSince1970] - 1) * 1000; video.isReadAcked = YES; video.deliveryState = eMessageDeliveryState_Delivered; video.isRead = YES; video.isGroup = _isChatGroup; video.conversationChatter = @"my_test5"; [[EaseMob sharedInstance].chatManager insertMessagesToDB:@[image, voice, video]]; [[EaseMob sharedInstance].chatManager loadAllConversationsFromDatabaseWithAppend2Chat:YES];}
解决方案五:
对的,你的消息数据要包成EMMessage对象,然后才能插入到db。
解决方案六:
但我是上面字典一组数据,- (NSInteger)insertMessagesToDB:(NSArray *)messages;这个数组装的是EMMessage对象是不是,要不要把我的字典数组转成模型后在给EMMessage对象传值