I am working on a group project where we have created a React Native app. Two of my team members worked on the server-side of the project and I am working on the client-side, the app works perfectly on Android but the http requests aren't working in iOS. I tried searching for solutions, most of them said that I need to add a few lines to the info.plist file, I tried all that but none of that worked so hopefully no one will mark this question as a duplicate.
I am stuck in the Login page of the app, here is the code: UserLogin.js
// This function is called when the login button is pressedsubmit=() => {// Some validationsif(Object.keys(this.state.success).length==0){ const URL="http://10.0.2.2:4000/userLogin" const loginconfirm = async () => { try { return await axios.post(URL,this.state) } catch (error) { console.error(error) } } const getloginconfirm = async () => { const confirm = await loginconfirm() if (confirm.data.message=="success") { alert("Successfully logged in") UserInfo.setName(confirm.data.name); UserInfo.setId(confirm.data.id); if(confirm.data.category=="Exporter"){ const {navigation} = this.props; navigation.navigate('ScreenMove') //Should go to ScreenMove.js }else{ const {navigation} = this.props; navigation.navigate('FarmerHomePage') } } else{alert("The username does not exist or password does not match the username")} } getloginconfirm();}
Here's my info.plist
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>CFBundleDevelopmentRegion</key><string>en</string><key>CFBundleDisplayName</key><string>UNAGI</string><key>CFBundleExecutable</key><string>$(EXECUTABLE_NAME)</string><key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string><key>CFBundleInfoDictionaryVersion</key><string>6.0</string><key>CFBundleName</key><string>$(PRODUCT_NAME)</string><key>CFBundlePackageType</key><string>APPL</string><key>CFBundleShortVersionString</key><string>1.0</string><key>CFBundleSignature</key><string>????</string><key>CFBundleURLTypes</key><array><dict/></array><key>CFBundleVersion</key><string>1</string><key>LSRequiresIPhoneOS</key><true/><key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/><key>NSExceptionDomains</key><dict><key>localhost</key><dict><key>NSIncludesSubdomains</key><false/><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict></dict><key>NSLocationWhenInUseUsageDescription</key><string></string><key>UILaunchStoryboardName</key><string>LaunchScreen</string><key>UIRequiredDeviceCapabilities</key><array><string>armv7</string></array><key>UISupportedInterfaceOrientations</key><array><string>UIInterfaceOrientationPortrait</string><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string></array><key>UIViewControllerBasedStatusBarAppearance</key><false/></dict></plist>
Here's the error I'm getting:
2020-04-29 20:02:04.589406+0530 UNAGI[30263:604617] [] nw_socket_handle_socket_event [C8:2] Socket SO_ERROR [60: Operation timed out] 2020-04-29 20:02:04.590542+0530 UNAGI[30263:604617] Connection 8: received failure notification 2020-04-29 20:02:04.592849+0530 UNAGI[30263:604617] Connection 8: failed to connect 1:60, reason -1 2020-04-29 20:02:04.594920+0530 UNAGI[30263:604617] Connection 8: encountered error(1:60) 2020-04-29 20:02:04.605649+0530 UNAGI[30263:604617] Task<695EDB52-BC43-4A20-93D2-A3481D44468C>.<3> HTTP load failed, 0/0 bytes (error code: -1001 [1:60]) 2020-04-29 20:02:04.622585+0530 UNAGI[30263:604513] Task <695EDB52-BC43-4A20-93D2-A3481D44468C>.<3> finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001"The request timed out." UserInfo={_kCFStreamErrorCodeKey=60, NSUnderlyingError=0x60000235c360 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <695EDB52-BC43-4A20-93D2-A3481D44468C>.<3>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <695EDB52-BC43-4A20-93D2-A3481D44468C>.<3>" ), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=http://10.0.2.2:4000/userLogin, NSErrorFailingURLKey=http://10.0.2.2:4000/userLogin, _kCFStreamErrorDomainKey=1} 2020-04-29 20:02:04.639 [error][tid:com.facebook.react.JavaScript] Error: timeout of 0ms exceeded 2020-04-29 20:02:04.761 [warn][tid:com.facebook.react.JavaScript] Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object (evaluating'confirm.data') getloginconfirm$@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:132789:32 tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30544:23 invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30720:32 tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30544:23 invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30620:30http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30630:21 tryCallOne@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3344:16http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3445:27 _callTimer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:32458:17 _callImmediatesPass@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:32494:19 callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:32712:33 callImmediates@[native code] __callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2752:35http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2538:34 __guard@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2735:15 flushedQueue@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2537:21 flushedQueue@[native code] callFunctionReturnFlushedQueue@[native code]
Appreciate the feedback! :)