QuickBlox - 对话框必须在 Objective-C 的内存缓存中
Posted
技术标签:
【中文标题】QuickBlox - 对话框必须在 Objective-C 的内存缓存中【英文标题】:QuickBlox - Dialog have to be in memory cache in Objective-C 【发布时间】:2017-05-05 10:45:49 【问题描述】:我创建了一个聊天应用程序。我已经使用 QuickBlox 互相聊天。
我已经注册了两个用户并互相聊天,它会很完美。 但是当用户注销并再次登录时,它会崩溃。
错误 - 对话框必须在内存缓存中!
EX:A 和 B 用户使用他们的设备登录,然后在他们注销并再次登录以及发送消息应用程序崩溃时相互聊天。 p>
登录
- (void)loginWithQuickBlox:(NSString *)idandPassword
[QBRequest logInWithUserLogin:idandPassword password:idandPassword successBlock:^(QBResponse *response, QBUUser *user)
// NSLog(@"User Id : %ld",(unsigned long)user.ID);
NSString *usrID=[NSString stringWithFormat:@"%ld",(unsigned long)user.ID];
[[NSUserDefaults standardUserDefaults]setObject:usrID forKey:@"LoginQuickbloxID"];
[self loginWithQuickBloxChat:idandPassword];
errorBlock:^(QBResponse *response)
// error handling
NSLog(@"error: %@", response.error);
];
- (void)loginWithQuickBloxChat:(NSString *)idandPassword
QBUUser *selectedUser = [QBUUser user];
selectedUser.password = idandPassword;
selectedUser.login = idandPassword;
[ServicesManager.instance logInWithUser:selectedUser completion:^(BOOL success, NSString *errorMessage)
if (success)
[self getRecenetChatUsingInBadgeCount];
NSLog(@"Login in Quickblox");
[[NSUserDefaults standardUserDefaults]setObject:idandPassword forKey:@"QuickbloxIDPass"];
else
NSLog(@"Error in QuickBlox");
];
聊天
与 ChatViewController 聊天。
注销
1)取消订阅设备令牌
NSString *deviceUdid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[QBRequest unregisterSubscriptionForUniqueDeviceIdentifier:deviceUdid successBlock:^(QBResponse *response)
// Unsubscribed successfully
NSLog(@"Unsubscribed successfully");
errorBlock:^(QBError *error)
// Handle error
NSLog(@"Unsubscribed ERROR");
];
2)ServicesManager 注销
[ServicesManager.instance logoutWithCompletion:^
NSLog(@"logoutWithCompletion");
];
3)退出成功阻止
[QBRequest logOutWithSuccessBlock:^(QBResponse *response)
// Successful logout
NSLog(@"Successful logout");
errorBlock:^(QBResponse *response)
// Handle error
NSLog(@"Logout ERROR %@",response);
];
退出登录后发送消息时再次崩溃
QMChatService.m
- (void)sendMessage:(QBChatMessage *)message
toDialogID:(NSString *)dialogID
saveToHistory:(BOOL)saveToHistory
saveToStorage:(BOOL)saveToStorage
completion:(QBChatCompletionBlock)completion
NSCParameterAssert(dialogID);
QBChatDialog *dialog = [self.dialogsMemoryStorage chatDialogWithID:dialogID];
NSAssert(dialog != nil, @"Dialog have to be in memory cache!");
[self sendMessage:message toDialog:dialog saveToHistory:saveToHistory saveToStorage:saveToStorage completion:completion];
【问题讨论】:
我有同样的问题,发送消息应用程序会在这里崩溃:NSAssert(dialog != nil, @"Dialog must be in memory cache!"); @sohil,请在Quickblox repo 中创建问题并附上完整的日志。 @sohil,你找到解决这个问题的方法了吗? 【参考方案1】:答案很晚,但也许有人会觉得这很有帮助。 为了使对话在内存中,必须使用正确的方法加载它(某些方法不执行此操作)。 这是我的做法(但很快,我很抱歉)
private func sendMessage(message: QBChatMessage)
if ServicesManager.instance().chatService.dialogsMemoryStorage.chatDialog(withID: self.dialog.id!) != nil
self.send(message: message)
else
loadAndSaveToMemoryDialog(message)
private func send(message: QBChatMessage)
ServicesManager.instance().chatService.send(message, toDialogID: self.dialog.id!, saveToHistory: true, saveToStorage: true) (error in
if error != nil
QMMessageNotificationManager.showNotification(withTitle: "SA_STR_ERROR", subtitle: error?.localizedDescription, type: .error, handler: nil)
private func loadAndSaveToMemoryDialog(_ message: QBChatMessage)
ServicesManager.instance().chatService.loadDialog(withID: self.dialog.id!)
[weak self] _ in
guard let self = self else return
self.sendMessage(message: message)
【讨论】:
以上是关于QuickBlox - 对话框必须在 Objective-C 的内存缓存中的主要内容,如果未能解决你的问题,请参考以下文章