Unhandled Exception: SocketException: OS Error on Disconnect

Hi all. I am new to Flutter. I am busy developing an app that uses MQTT all works fine on Android but the app will crash randomly on iOS if I placed the app in the background and bring it to the foreground again.

I use the LifeCycleState to see if the app goes to the background and then disconnects from the message broker. And then reconnect when the app gets focus again. This works 100% on Android and the iOS simulator but will randomly crash on iOS Devices.

I did also log an issue with the MQTT lib developer and he says it is a Flutter / Dart issue.

//Check if the app was placed in the background
  void didChangeAppLifecycleState(AppLifecycleState state) {

    if (state == AppLifecycleState.inactive ||
        state == AppLifecycleState.detached) {

    //If the app is in the background
    if (state == AppLifecycleState.paused) {
    //If we bring the app to the foreground again
    if (firstRun == true) {
      if (state == AppLifecycleState.resumed) {

How do I get the logs files from the iOS device?

Hi. Is anybody able to point me in the correct direction?