Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rash6795 opened this issue Jan 10, 2018 · 5 comments
Closed

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

rash6795 opened this issue Jan 10, 2018 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@rash6795
Copy link

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

@rash6795 rash6795 changed the title Platform.OS returns android when running in iOS device Platform.OS returns 'android' when running in iOS device Jan 10, 2018
@compojoom
Copy link
Contributor

Can't reproduce this. Have you run android version of the app before testing in android? Did you close the packager/debugger - this shouldn't matter though.

@froatsnook
Copy link

Are you sure it's returning "android"? Trying changing it to: console.log(Platform.OS). Maybe you've imported Platform incorrectly?

@rash6795
Copy link
Author

@froatsnook yes tried that too it still prints android . And the import statement is import {Platform} from 'react-native';

@rash6795
Copy link
Author

@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.

@rash6795
Copy link
Author

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

@facebook facebook locked as resolved and limited conversation to collaborators Jan 11, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants