Platform.OS returns 'android' when running in iOS device
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS High Sierra 10.13.2 Node: 8.9.2 Yarn: Not Found npm: 5.5.1 Watchman: Not Found Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4408382
Packages: (wanted => installed) react: 16.0.0-beta.5 => 16.0.0-beta.5 react-native: 0.50.3 => 0.50.3
Target Platform: iOS (8.0)
Steps to Reproduce
- Paste below code in your
index.js
componentDidMount() {
if(Platform.OS === 'ios') {
console.log(" ios")
} else {
console.log("android")
}
}
- Enable Remote JS Debugging and check the Console for log
Expected Behavior
Console Log Output: ios
Actual Behavior
Console Log Output:
Simulator Output:
checkInitialPermissions is the function to be executed only on android. But its executed on iOS.
Reproducible Demo
Follow steps to reproduce
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Platform Specific Code - React Native
Platform.OS will be ios when running on iOS and android when running on Android. There is also a Platform.select method available, ...
Read more >How to use Platform.OS to elements in react native?
I want to use just KeyboardAwareScrollView without any functions on IOS and given below code for android. I know ...
Read more >React Native Platform - To Detect Android or iOS Device
1 React Native Platform · 2 To Import Platform in Code · 3 Detect Device Using · 4 To Make a React Native...
Read more >A guide to platform select and platform specific files in React ...
If they're running an iOS device it will return the value of the iOS key, if Android it will return the value of...
Read more >Platform | Ionic Documentation
Note that the same app can return true for more than one platform name. For example, an app running from an iPad would...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry it was my mistake in render method i had given
Platform.OS = 'android'
instead ofPlatform.OS == 'android'
so after the render method when the componentDidMount is called thePlatform.OS was assigned as android
@compojoom yes android works fine as expected. the same code when i try to run for ios is giving the android output instead of ios output
I tried
removing the node modules and installing it again
.Teminated react packager and started all over
.Clean & Build
also restartingxcode
also didn’t help.