Platform not detected correctly on Android (Platform.OS)
See original GitHub issueDescription
The issue is simple, Platform
is not detecting Android correctly in some instances. I am only ever able to reproduce the issue when I save my App.js
file and React Native reloads the app. This is causing the OneSignal SDK package that also uses Platform
to fall into an iOS-only code path (here).
React Native version:
System:
OS: macOS 10.15.5
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 87.29 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.0 - /usr/local/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.8.4 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
API Levels: 24, 26, 27, 28, 29
Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.0, 29.0.2
System Images: android-23 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_191 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.9.0 => 16.9.0
react-native: ^0.63.3 => 0.63.3
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
- Clone project
git clone https://github.com/OneSignal/react-native-onesignal.git
cd react-native-onesignal/examples/RNOneSignal
git checkout react-native-issue-repro
yarn install
-
Open the
android
directory with Android Studio and fix any build issues like signing config keystore , gradle, etc… -
react-native run-android
-
Send yourself a notification by tapping the button “Post a Notification”
-
Open App.js, on line 401 try playing with the 3rd argument. Change the line to
OneSignal.postNotification({en:"Testing this post"}, {data:"data"}, state.userId);
(i.e. remove the brackets from the last argument).
Somehow I can consistently reproduce the issue by doing that (send notif, remove brackets, save).
Expected Results
I expect the log not to print that the platform is iOS, since I am running this on Android.
Snack, code example, screenshot, or link to a repository:
See line 394 in App.js from the repository.
import { Platform } from 'react-native';
if (Platform.OS === 'ios') console.log("Platform is iOS");
SCREENSHOTS

Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6
Just an update from my side, this was my user error. I found an instance in my app where I had accidentally tried to assign Platform.OS a value (I.e. Platform.OS = “ios”). This broke the Platform module and it never recovered until a restart.
similar problem, but my Platform.OS resolves to “false”. This breaks linkages to native components and crashes the app. e.g.
Invariant Violation: requireNativeComponent: "RCTSwitch" was not found in the UIManager.
Any idea how to fix this?