question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Platform.OS returns 'android' when running in iOS device

See original GitHub issue

Is 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

  1. Paste below code in your index.js
componentDidMount() {
        if(Platform.OS === 'ios') {
	       console.log(" ios") 
        } else {
              console.log("android") 
       } 
}
  1. Enable Remote JS Debugging and check the Console for log

Expected Behavior

Console Log Output: ios

Actual Behavior

Console Log Output:

screen shot 2018-01-10 at 6 14 10 pm

Simulator Output: screen shot 2018-01-10 at 6 15 34 pm

checkInitialPermissions is the function to be executed only on android. But its executed on iOS.

Reproducible Demo

Follow steps to reproduce

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rash6795commented, Jan 11, 2018

Sorry it was my mistake in render method i had given Platform.OS = 'android' instead of Platform.OS == 'android' so after the render method when the componentDidMount is called the Platform.OS was assigned as android

0reactions
rash6795commented, Jan 11, 2018

@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 restarting xcode also didn’t help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found