我的第一篇文章。我已经搜索了很多关于在Core Data中存储/存档消息的问题和答案,我似乎无法破解它。
我可能会做一些非常愚蠢的事情,所以任何帮助都会受到赞赏。
在此处设置我的信息流:
-(void)setupStream {
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
XMPPMessageArchivingCoreDataStorage *xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
XMPPMessageArchiving *xmppMessageArchivingModule = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];
[xmppMessageArchivingModule setClientSideMessageArchivingOnly:YES];
[xmppMessageArchivingModule activate:xmppStream];
[xmppMessageArchivingModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
尝试在此处测试我的存档:
-(void) testMessageArchive {
XMPPMessageArchivingCoreDataStorage *storage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [storage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Contact_CoreDataObject"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
NSError *error;
NSArray *messages = [moc executeFetchRequest:request error:&error];
}
问题是我似乎无法从消息对象中获取任何合理的信息。内容如下。我是否需要深入了解消息文本和发件人? messages数组中有一个对象,这是正确的,因为我只发送了一条消息。消息数组中的项目是:
> <_PFArray 0x10f0021a0>( <XMPPMessageArchiving_Contact_CoreDataObject:
> 0x1099de1b0> (entity: XMPPMessageArchiving_Contact_CoreDataObject; id:
> 0xd000000000040000
> <x-coredata://1013D7F5-A511-45F0-B719-13EEF1DD32A3/XMPPMessageArchiving_Contact_CoreDataObject/p1>
> ; data: <fault>) )