【发布时间】:2014-01-05 08:44:49
【问题描述】:
我将 Quickblox 用于我的聊天应用程序,并使用核心数据来存储消息历史记录。
当我登录聊天时,我重新发送了上次发送失败的消息。 (即我从 Core Data 获取消息并获取未发送的消息)
有时它可以工作,但有时应用程序在辅助方法(用于获取核心数据上下文)上崩溃:
+ (NSManagedObjectContext *)context {
return ((AppDelegate *)[UIApplication sharedApplication].delegate).managedObjectContext;
}
我没有为 App Delegate 更改任何内容,它只是一个普通的启用 CoreData 的 AppDelegate:
@interface AppDelegate : UIResponder <UIApplicationDelegate, QBActionStatusDelegate, QBChatDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
这就是我在 DBHelper 类中检索消息历史记录的方式
+ (NSMutableArray *)fetchMessagesWithSenderID:(NSString *)userID {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Message" inManagedObjectContext:[DBHelper context]]; //the app crashes here, inside [DBHelper context]
[fetchRequest setEntity:entity];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"sender.userID = %@", userID];
[fetchRequest setPredicate:pred];
NSError *error;
NSMutableArray *fetchedObjects = [[DBHelper context] executeFetchRequest:fetchRequest error:&error].mutableCopy;
return fetchedObjects;
}
日志:
2014-01-05 16:32:05.365 Chat[1517:60b] completedWithResult: <QBMRegisterSubscriptionTaskResult: 0x14e955e0>
2014-01-05 16:32:05.366 Chat[1517:60b] error: (
"Invalid provisioning profiles. You have to use valid Provisioning Profiles for your project"
)
2014-01-05 16:32:06.549 Chat[1517:180f] QBChat/didConnect
2014-01-05 16:32:07.913 Chat[1517:4103] -[QBChat xmppStreamDidAuthenticate:] -> user: 573782, supportsStartTLS: 1, isSecure: 0
2014-01-05 16:32:07.913 Chat[1517:60b] chatDidLogin
2014-01-05 16:32:07.916 Chat[1517:60b] -[QBMGetTokenPerformer managedObjectContext]: unrecognized selector sent to instance 0x14d48800
(lldb)
【问题讨论】:
标签: ios core-data crash chat quickblox