Intercom.getUnreadStream() works wrong on iOS
Intercom.getUnreadStream() listener handles callback on iOS only once, after that it doesn't receive new emitted events. On Android everything works properly.
Unread stream initializes on the main page inside initState(). Probably UnreadStreamHandler inside iOS project initialized wrong.
intercom_flutter: ^6.0.0
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.10.2, on macOS 12.0.1 21A559 darwin-x64, locale en-RU) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc4) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.1) [✓] VS Code (version 1.64.2)
@override
void initState() {
super.initState();
_listenUnreadMessages();
}
void _listenUnreadMessages() => context.dispatch(ListenUnreadIntercomConversationsAction());
class ListenUnreadIntercomConversationsAction extends BaseAction {
@override
FutureOr<AppState?> reduce() {
final intercomService = GetIt.I.get<IntercomService>();
intercomService.getUnreadStream().listen((messagesCount) {
dispatch(UpdateIntercomConversationsCountAction(messagesCount));
}, onError: (error, st) {
print('!!!!!! INTERCOM ERROR');
});
return null;
}
}
class UpdateIntercomConversationsCountAction extends BaseAction {
UpdateIntercomConversationsCountAction(this.messagesCount);
final int messagesCount;
@override
Operation get operationKey => Operation.updateUnreadIntercomMessages;
@override
FutureOr<AppState> reduce() async {
return state.rebuild(
(b) => b.mailState..unreadIntercomCount = messagesCount,
);
}
}
The same happens on 6.2.0 for me. Also, it does not work if I periodically poll with Intercom.unreadConversationCount() instead of using a stream. This may be a sign of Intercom iOS SDK not receiving new messages if not explicitly opened.
Just had another look and the issue seems to be related to Flutter update to 2.10. Stream was working right before. But, after the update, StreamBuilder's snapshot.connectionState returns waiting with no state update later. (Only iOS is affected)