Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

can't fetch from iphone device to my localhost using expo - react native

$
0
0

I am on the very first steps of my app creation. currently on the sign-in/sign-up screens. I'm trying to fetch from my iPhone device, using expo, to my server-side on my computer, but from some reason it doesn't work. so after long searches on the internet, these are the steps I've already done:

relevant code bellow:

const LoginScreen = ({ navigation }) => {

  const [email, setEmail] = useState({ value: '', error: '' });
  const [password, setPassword] = useState({ value: '', error: '' });

   const apiUrl = 'http://192.168.X.X:49948/api/Tourist';

  const _onLoginPressed = () => {
    const emailError = emailValidator(email.value);
    const passwordError = passwordValidator(password.value);

    if (emailError || passwordError) {
      setEmail({ ...email, error: emailError });
      setPassword({ ...password, error: passwordError });
      return;
    }
    else{

    const user = {
      Email: email.value,
      PasswordTourist: password.value
    };

    fetch(apiUrl, {
      method: 'POST',
      body: JSON.stringify(user),
      headers: new Headers({
        'Content-type': 'application/json; charset=UTF-8' //very important to add the 'charset=UTF-8'!!!!
      })

    })
      .then(res => {
        console.warn('res=', res);
        return res.json()
      })
      .then(
        (result) => {
          console.warn("fetch POST= ", result);
        },
        (error) => {
          console.warn("err post=", error);
        });

     // navigation.navigate('Dashboard');
    }


  };

app.json:

{
  "expo": {
    "name": "Blank Template",
    "slug": "IsraVisor",
    "privacy": "public",
    "sdkVersion": "36.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "config" :{
        "googleSignIn":{
          "reservedClientId": "com.googleusercontent.apps.369112967382-tqc9ttloirgp9ne76rfmbdc3upmv26kf"
        }
      }
    }
  }
}

package.json:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/vector-icons": "^10.0.6",
    "@react-native-community/google-signin": "^3.0.4",
    "@react-native-community/masked-view": "^0.1.5",
    "axios": "^0.19.2",
    "expo": "~36.0.0",
    "expo-facebook": "~8.0.0",
    "expo-google-app-auth": "^8.0.1",
    "link": "^0.1.5",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
    "react-native-elements": "^1.2.7",
    "react-native-fbsdk": "^1.1.2",
    "react-native-gesture-handler": "~1.5.0",
    "react-native-google-signin": "^2.1.1",
    "react-native-link": "^4.1.0",
    "react-native-paper": "^3.6.0",
    "react-native-reanimated": "~1.4.0",
    "react-native-safe-area-context": "0.6.0",
    "react-native-screens": "2.0.0-alpha.12",
    "react-native-status-bar-height": "^2.4.0",
    "react-native-web": "~0.11.7",
    "react-native-webview": "^8.1.2",
    "react-navigation": "^4.2.2",
    "react-navigation-stack": "^2.2.2",
    "react-navigation-tabs": "^2.8.2"
  },
  "devDependencies": {
    "babel-preset-expo": "~8.0.0",
    "@babel/core": "^7.0.0"
  },
  "private": true
}

thank you all!


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>