Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if my React-Native app is running in a web broswer vs running in an ios/android app?

Basically what the title says. I am aware of the Platform component (https://reactnative.dev/docs/platform-specific-code) which can be used to check what device the app is running on. Although, from my understanding, if the app is running in a web browser on ios/android, Platform wouldn't identify if it's running as an app or in a browser. Can I maybe do something like document == 'undefined (true if browser, false if app)? I appreciate any guidance.

I'm using expo by the way.

like image 542
Nick Pfeiffer Avatar asked Feb 01 '26 20:02

Nick Pfeiffer


1 Answers

import { Platform } from 'react-native';

if (Platform.OS === 'ios') {
  // do something for ios
} else if (Platform.OS === 'android') {
  // other thing for android
} else if (Platform.OS === 'web') {
  // it's on web!
} else {
  // you probably won't end up here unless you support another platform!
}

I would recommend following the full tutorial provided at the start of the Expo docs, the Handling platform differences section covers this and you may learn other valuable information from the other sections.

like image 64
brentvatne Avatar answered Feb 04 '26 10:02

brentvatne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!