I cant reach my API on iOS emulator. The same code runs perfectly on the Android emulator. I tried a couple of other APIs just to test and everything works as intended (JSONPlaceholder with HTTPS and some random one that uses HTTP. Both GET and POST work fine).
Code example of my fetch call:
const login = async (authData) => { console.log('fetching...'); //Setting up the request //Select apropriate port 8515 | 8516 const port = handlePortSelection(authData.username); const url = `http:\\xxx.xxx.xxx.xxx:${port}/api/Auth/LoginUser`; const headers = {'Content-Type': 'application/json; charset=UTF-8'}; const body = JSON.stringify(authData); const requestOptions = { method: 'POST', headers: headers, body: body }; try { //Call API const response = await fetch(url, requestOptions); const data = await response.json(); setUserData(data); } catch (error) { console.error(error); }};
My Info.plist file:
<dict><key>NSAllowsArbitraryLoads</key><true/><key>NSExceptionDomains</key><dict><key>localhost</key><dict><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict></dict>
iOS emulator error and Call Stack screenshot
Here is my react-native info:
System:OS: macOS Mojave 10.14.6CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHzMemory: 31.91 MB / 8.00 GBShell: 5.3 - /bin/zshBinaries:Node: 14.6.0 - ~/.nvm/versions/node/v14.6.0/bin/nodeYarn: 1.22.5 - /usr/local/bin/yarnnpm: 6.14.6 - ~/.nvm/versions/node/v14.6.0/bin/npmWatchman: 4.9.0 - /usr/local/bin/watchmanManagers:CocoaPods: 1.9.3 - /usr/local/bin/podSDKs:iOS SDK:Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1Android SDK:API Levels: 28, 29, 30Build Tools: 28.0.3, 29.0.2, 30.0.2System Images: android-29 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 AtomAndroid NDK: Not FoundIDEs:Android Studio: 4.0 AI-193.6911.18.40.6626763Xcode: 11.3.1/11C505 - /usr/bin/xcodebuildLanguages:Java: 1.8.0_265 - /usr/bin/javacPython: 2.7.16 - /usr/bin/pythonnpmPackages:@react-native-community/cli: Not Foundreact: 16.13.1 => 16.13.1react-native: 0.63.2 => 0.63.2react-native-macos: Not FoundnpmGlobalPackages:react-native: Not Found
Any help wold be greatly appreciated! Tnx :)