React-native: Xcode 9 Runtime error: -[UIApplication applicationState] must be used from main thread

Created on 11 Oct 2017  路  12Comments  路  Source: facebook/react-native

Is this a bug report?

Yes

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.6.0
Yarn: 1.2.0
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: Not Found

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.3 => 0.49.3

Steps to Reproduce

  1. Open Xcode
  2. Run on device (iPhone 6s)
  3. Hit runtime error

Expected Behavior

No runtime error.

Actual Behavior

Runtime error:

screenshot 2017-10-10 20 49 19

Reproducible Demo

My package.json:

{
  "name": "[PROJECT]",
  "version": "0.0.1",
  "private": true,
  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
        "jsx": true,
        "experimentalObjectRestSpread": true
      }
    },
    "env": {
      "browser": true,
      "node": true
    },
    "plugins": [
      "react",
      "react-native"
    ],
    "rules": {
      "comma-dangle": [
        2,
        "always-multiline"
      ],
      "semi": [
        2,
        "never"
      ],
      "react-native/no-unused-styles": 2,
      "react-native/split-platform-components": 2
    }
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "babel-plugin-idx": "^2",
    "he": "^1.1.0",
    "jssha": "^2.3.1",
    "lodash": "^4.17.2",
    "moment-timezone": "^0.5.10",
    "node-summary": "../node-summary",
    "react": "16.0.0-beta.5",
    "react-native": "0.49.3",
    "react-native-blur": "^3.1",
    "react-native-code-push": "5.1.3-beta",
    "react-native-firebase": "^3.0",
    "react-native-fit-image": "^1.4.8",
    "react-native-highlight-words": "smartkarma/react-native-highlight-words",
    "react-native-keep-awake": "envoy/react-native-keep-awake",
    "react-native-linear-gradient": "^2.0.0",
    "react-native-modalbox": "^1.3.8",
    "react-native-notification": "../react-native-notification",
    "react-native-orientation": "^3.0.0",
    "react-native-parallax-scroll-view": "../react-native-parallax-scroll-view",
    "react-native-safari-view": "^2.0.0",
    "react-native-sentry": "^0.26",
    "react-native-status-bar-size": "^0.3.2",
    "react-native-swiper": "^1.5.10",
    "react-native-tooltip": "../react-native-tooltip",
    "react-native-tts": "^1.3.0",
    "react-native-vector-icons": "^4.1.1",
    "react-native-webview-bridge": "../react-native-webview-bridge-RN0.40",
    "react-redux": "^5.0.1",
    "redux": "^3.6.0",
    "redux-thunk": "^2.1.0"
  },
  "devDependencies": {
    "redux-logger": "^3.0.6"
  },
  "resolutions": {
    "moment-timezone/moment": "^2.19.0"
  }
}
Locked

Most helpful comment

It would be really nice to have that bugfix backported to a 0.49 patch release.

I can't finish my upgrade to 0.49 because this breaks 0.49 in our iOS build. It would be preferable to not have to wait till the end of the month for 0.50 to finally get a release because of a 0.49 regression.

All 12 comments

I'm getting this error too.

Environment:
OS: macOS Sierra 10.12.6
Node: 8.6.0
Yarn: 1.0.2
npm: 4.6.1
Watchman: 4.7.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.3 => 0.49.3
react-native-document-picker: dev

This was fixed in e8c83d1

It would be really nice to have that bugfix backported to a 0.49 patch release.

I can't finish my upgrade to 0.49 because this breaks 0.49 in our iOS build. It would be preferable to not have to wait till the end of the month for 0.50 to finally get a release because of a 0.49 regression.

This fix allow to use fastlane screenshot feature!
If you can't wait for 0.50, you can just patch by hand the file, it's working (better than nothing)

Hi @MoOx, I'm a bit new to this and not clear how to fix this manually. Would you be able to elaborate? Unfortunately I have my hands tied and must use 0.49.3.

You can apply this patch, by hand https://github.com/facebook/react-native/commit/e8c83d180f1691baf61a68323d95299354c7bde6 in Libraries/React directly from you project via Xcode.

I confirm fixed since RN 0.50.

I'm using RN 0.41.2... but there is no requiresMainQueueSetup method in that react file. Anyone know an alternative solution?

Upgrade RN.

@fungilation Last time I tried upgrading RN, it took me 3 hours to give up and revert back to 0.41.2. I鈥檝e been working on a project for about a year and it鈥檚 not exactly easy to upgrade anymore. Especially with all the third party modules I鈥檓 using that may or may not work. I expect a week of work to upgrade and fix everything that breaks. Any better ideas?

Nope. There's no such thing as backporting fixes in RN. You can do it yourself, or do what I do. Religiously upgrade to the latest RN versions every version to avoid non-upgradeablity. react-native-git-upgrade works every time now. Shit still break on .0 releases, so to spare some pain and suffering, trail behind latest by 1 release. Aka. latest RN is 0.53.3, you can stick with 0.52.x before 0.54 comes out

@KjellConnelly I feel your pain. Definitely have to stay behind the latest release by at least a full middle-version number, as most 3rd party modules are not as quick to upgrade either. Upgrading React Native is easily the most painful/unsavory part of the framework.

Was this page helpful?
0 / 5 - 0 ratings