fix chatroominfoview crash by reconfiguring the chatroom after entering background puis foreground

This commit is contained in:
Danmei Chen 2022-02-10 16:17:55 +01:00
parent 0fdde4a56d
commit f9bddedf79
4 changed files with 32 additions and 18 deletions

View file

@ -34,6 +34,7 @@
@property(nonatomic) NSString *oldSubject;
@property(nonatomic) LinphoneChatRoom *room;
@property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs;
@property(nonatomic) const char *peerAddress;
@property (weak, nonatomic) IBOutlet UIIconButton *nextButton;
@property (weak, nonatomic) IBOutlet UIRoundBorderedButton *quitButton;
@ -49,6 +50,4 @@
- (IBAction)onBackClick:(id)sender;
- (IBAction)onQuitClick:(id)sender;
- (void)removeCallbacks;
@end

View file

@ -83,12 +83,30 @@ static UICompositeViewDescription *compositeDescription = nil;
_oldContacts = [[NSMutableArray alloc] init];
_room = NULL;
_chatRoomCbs = NULL;
_peerAddress = NULL;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_waitView.hidden = YES;
[self configure];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(onLinphoneCoreReady:)
name:kLinphoneGlobalStateUpdate
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[NSNotificationCenter.defaultCenter removeObserver:self];
if (!_room || !_chatRoomCbs)
return;
linphone_chat_room_remove_callbacks(_room, _chatRoomCbs);
_chatRoomCbs = NULL;
}
- (void)configure {
if (_create)
_room = NULL;
@ -131,20 +149,20 @@ static UICompositeViewDescription *compositeDescription = nil;
[_tableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
[self removeCallbacks];
}
- (void)removeCallbacks {
if (!_room || !_chatRoomCbs)
return;
linphone_chat_room_remove_callbacks(_room, _chatRoomCbs);
_chatRoomCbs = NULL;
}
#pragma mark - next functions
- (void)onLinphoneCoreReady:(NSNotification *)notif {
if ((LinphoneGlobalState)[[[notif userInfo] valueForKey:@"state"] integerValue] == LinphoneGlobalOn) {
if (!_create && _peerAddress) {
LinphoneAddress *peerAddr = linphone_core_create_address([LinphoneManager getLc], _peerAddress);
if (peerAddr) {
_room = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr);
}
[self configure];
}
}
}
- (void)onCreate {
bctbx_list_t *addresses = NULL;
for (NSString *addr in _contacts) {

View file

@ -888,6 +888,7 @@ static UICompositeViewDescription *compositeDescription = nil;
view.oldAdmins = [admins mutableCopy];
view.oldSubject = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_chatRoom) ?: LINPHONE_DUMMY_SUBJECT];
view.room = _chatRoom;
view.peerAddress = _peerAddress;
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
}

View file

@ -69,10 +69,6 @@
[view removeCallBacks];
[view.tableController setChatRoom:NULL];
[view setChatRoom:NULL];
} else if (PhoneMainView.instance.currentView == ChatConversationInfoView.compositeViewDescription) {
ChatConversationInfoView *view = VIEW(ChatConversationInfoView);
[view removeCallbacks];
[view setRoom:NULL];
} else if (PhoneMainView.instance.currentView == RecordingsListView.compositeViewDescription || PhoneMainView.instance.currentView == DevicesListView.compositeViewDescription) {
// To avoid crash
[PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];